php: replacing double <br /> with </p><p>
- by andufo
i use nicEdit to write RTF data in my CMS. The problem is that it generates strings like this:
hello first line<br><br />this is a second line<br />this is a 3rd line
since this is for a news site, i much prefer the final html to be like this:
<p>hello first line</p><p>this is a second line<br />this is a 3rd line</p>
so my current solution is this:
i need to trim the $data for <br /> at the start/end of the string
replace <br /><br /> with </p><p> (one single <br /> is allowed).
finally, add <p> at the start and </p> at the end
i only have the 3rd step so far. can someone give me a hand with steps 1 and 2?
function replace_br($data) {
# step 3
$data = '<p>'.$data.'</p>';
return $data;
}
thanks!
ps: it would be even better to avoid specific situations. example: "hello<br /><br /><br /><br /><br />too much space" -- those 5 breaklines should also be converted to just one "</p><p>"