agahi agahi -5 years ago 92
PHP Question

removing unknown number of tags from inside a tag

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.

Answer Source

Change your REGEX to:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download