How to find line break in php?

Sorry I'm not that good with PHP yet, I tried this to find it and then put each row 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?

+5
source share
3 answers
$it = explode("\n", $translate);

http://php.net/explode

:)

+16
source

Updated:

it may cause an unexpected line break, this option may help:

$arry_lines = explode("[\n|\r]", $translate);
+2
source

You can do $ string = nl2br ($ string) so that your line break is changed to

<br />. 

Then you can manipulate the string, for example. split it into first appearance

<br />

like this:

list($first, $second) = explode('<br />', $string, 2);
0
source

All Articles