Reputation: 59
I have these string:
$st = '<p><br/></p>';
$st = '<p><br/><br/></p>';
$st = '<p><br/><br/><br/></p>';
How can I remove all the line breaks from inside the P tag? I tried this but didn't work:
echo preg_replace('/p>(br\/>)*?<\/p/','p></p',$st);
I'm sorry, seem I need to explain. more. This would be inside a larger text and I don't want to remove all the line breaks. Only those which are inside a P tag with unknown number of occurance.
Upvotes: 1
Views: 46
Reputation: 1493
There are some non-RegEx alternatives,
Using str_replace;
echo str_replace("<br/>","",$st );
Using strip_tags;
echo strip_tags($st,"<p>");
Upvotes: 0
Reputation: 3795
Change your REGEX to:
preg_replace('#p\>(\<br\/\>)*?\<\/p#','p></p',$st)
Upvotes: 2