php - Strip HTML string but don't lose line breaks -
i have string contains lot of html (html email body).
what want lose html keep line breaks, tried strip_tags() didn't work out me, makes string 1 line.
after has been done, want echo first 5 lines string.
anyone got idea?
update:
$string = strip_tags($string, '<p><br><br />'); seems working, have select first 5 lines string, idea?
update: array keeps giving few empty values. managed remove empty ones array doesn't restart counting. array looks now:
array ( [8] => dit een nieuwe test met meerdere regels. [9] => dit regel nummer 2. [10] => dit regel nummer 3. but should start counting @ 0 again.
array_filter() array_merge() etc. not work.
use strip_tags second parameter, this: strip_tags($html, '<p><br>'). can see, second parameter takes in $allowable_tags in docs ..
see this question/answer also.
perhaps easiest first few lines using explode:
$lines = explode("<br>", $string); // take first 5 array exploding new lines get lines of course using $lines[0] (1st line), $lines[1] (2nd line) etc.
Comments
Post a Comment