How do you find a line break in php?
12,726
Solution 1
$it = explode("\n", $translate);
:)
Solution 2
Updated:
it can produce an unexpected linebreak, this variation may help:
$arry_lines = explode("[\n|\r]", $translate);
Author by
SDuke
Updated on July 26, 2022Comments
-
SDuke almost 2 years
Sorry I ain't that good with PHP yet, I tried this to find it and then put each line in an array
$translate="this is in multiple lines"; $lastBreak=0; $it=array(); $ci=0; for ($i=1;$i<strlen($translate);$i++) { if strchr(substr($translate,$i,$i),"\n") { $it[$ci]=substr($translate,$lastBreak+1,$i-1); $ci+=1; $lastBreak=$i; } }
help?
-
Gromski about 13 years
split
is deprecated as of PHP 5.3 and shouldn't be used anymore. -
dfmiller over 11 yearsThe explode function does not allow a regular expression. Use preg_split instead: $arry_lines = preg_split("/[\r|\n]+/", $translate);
-
dfmiller over 11 yearsTo handle all line delimiters, use a regular expression in preg_split: $arry_lines = preg_split("/[\r|\n]+/", $translate);