Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

break text into an array : php

Options
  • 26-10-2007 9:00pm
    #1
    Registered Users Posts: 648 ✭✭✭


    hi,
    i have text in a variable and i want to break the text into an array broken down line by line.
    how do i do that ?

    tnx


Comments

  • Registered Users Posts: 6,511 ✭✭✭daymobrew


    Look at the split function. Some useful examples in the 'User contributed notes' section.


  • Registered Users Posts: 1,045 ✭✭✭Bluefrog


    $lines = explode('\n' $yourstring);

    I like explode - mainly because it's called explode...


  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    Bluefrog wrote: »
    I like explode - mainly because it's called explode...
    Yeah same here actually... implode too. :)

    Might want to str_replace the remaining \r's too if line breaks are coming in as \r\n ... or make something more elaborate to detect which line-breaks are present... I can never remember which ones are unix/windows... gonna have to look that up some day.


  • Registered Users Posts: 3,401 ✭✭✭randombar


    yup, explode is de job!


  • Registered Users Posts: 6,511 ✭✭✭daymobrew


    explode is perfect when the delimiter is static, while split is for when the delimiter changes as you can use a regular expression for the delimiter.


  • Advertisement
Advertisement