Search code examples
phpregexsplitline-endings

split string by rows


I have a string like so:

diverr_daily_report_2013-10-21_02:00:48_diverr_users_20_10_2013csv.csv
diverr_daily_report_2013-10-22_09:10:02_diverr_users_21_10_2013csv.csv

and i want to split it into elements.

output should look like:

[0]diverr_daily_report_2013-10-21_02:00:48_diverr_users_20_10_2013csv.csv
[1]diverr_daily_report_2013-10-22_09:10:02_diverr_users_21_10_2013csv.csv    

i was thinking to use the first and last word as a needle(they never chnage) : "diverr,csv"

what is a good way of doing this?
thanks


Solution

  • Just split it by end-of-line:

    $result = explode("\r\n", $your_string);
    

    or if Unix, then:

    $result = explode("\n", $your_string);