php - Return number of lines from a string base on a character -
In PHP, how do I return 6th or 5th or 4th rows from the string that looks like below? Add a new row to the four & lt; Br / & gt;
.
Therefore, if I have such a string
$ lines = 4; $ Song = 'line1 & lt; Br / & gt; Line 2 & lt; Br / & gt; Line 3 & lt; Br / & gt; & Lt; Br / & gt; Line 5 & lt; Br / & gt; Line 6 & lt; Br / & gt; Line 7 & lt; Br / & gt; Line 8 ';
It should be returned
line1 & lt; Br / & gt; Line 2 & lt; Br / & gt; Line 3 & lt; Br / & gt; Line 4
if I have
$ lines = 4; $ Song = 'line1 & lt; Br / & gt; Line 2 ';
It should be returned
line1 & lt; Br / & gt; Line 2
By dividing the string into an array, before the first array created < Em> n to get the element. Finally join them again.
$ n = 4; $ Song = 'line1 & lt; Br / & gt; Line 2 & lt; Br / & gt; Line 3 & lt; Br / & gt; & Lt; Br / & gt; Line 5 & lt; Br / & gt; Line 6 & lt; Br / & gt; Line 7 & lt; Br / & gt; Line 8 '; $ Rows = explosion ('& lt; br / & gt;', $ song); Echo Flat ('& lt; br / & gt;', array_slice ($ rows, 0, $ n));
Comments
Post a Comment