Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

break text into an array : php

  • 26-10-2007 08:00PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 6,733 ✭✭✭daymobrew


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


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


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

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


  • Closed Accounts Posts: 7,144 ✭✭✭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, Registered Users 2 Posts: 3,507 ✭✭✭randombar


    yup, explode is de job!


  • Registered Users, Registered Users 2 Posts: 6,733 ✭✭✭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
Advertisement