Is it possible to replace all the <br> tags with <p></p> with the PHP tools?
|
1 answer
try this
function replace_br($data) { $data = preg_replace('#(?:<br\s*/?>\s*?){1,}#', '</p><p>', $data); return "<p>$data</p>"; } Option number 2 (by Visman)
function replace_br($data) { $data = preg_replace('#(?:<br\s*/?>\s*?)+#', '</p><p>', $data); return "<p>$data</p>"; } - oneTwo or more
<br>({2,}) per pair</p><p>? - Dmitriy Simushev - you can and so, just thought easier to remove than add - Saidolim
- oneYour regular expression does not match the single
<br>tag. Proof: ideone.com/45rBAr - Dmitriy Simushev - @DmitriySimushev thanks a lot, fixed - Saidolim
- 2
{1,}is+. - Visman
|
str_replace. Only probably<br>better to replace with</p><p>- cyadvert