Get line 2 to line 5 in string

Hi,
i use this code for get only line 2 (= x y z):
$stringline2 =explode("\n",$string);
$result = $stringline2[1];

How can i get data in line 2-5 of string, eg:
“a b c
x y z
m l k
bla bla
bla bla
bla bla
bla bla”

if row 3-5 = no data => display only row 2…
Thank in advance

$stringline2 =explode("\n",$string);
$result = $stringline2[1]."<br>".$stringline2[2]."<br>".$stringline2[3]."<br>".$stringline2[4]."<br>".$stringline2[5];

Assuming you want to display them. Otherwise change the < br >'s to whatever is needed…
( Empty values might throw an error depending on how you created $stringline2! In that case, you would need to use a foreach and check if they exist. )

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service