Dennie
asked on
php strip empty html tags
Hi Experts!
With Curl my script receives HTML code from a website. From that source I would like to strip all empty tags such as <p> </p>
Somehow I can't seem to remove them, I think it has something to do with character settings or something. This is what I've tried:
$html = preg_replace('/<[^\/>]*>([ \s]?)*<\/[ ^>]*>/','' , $html);
$html = preg_replace('%<p></p>%',' ' , $html);
$html = preg_replace('%<p> </p>%','' , $html);
$html = str_replace('<p> </p>','',$html);
Any suggestions?
With Curl my script receives HTML code from a website. From that source I would like to strip all empty tags such as <p> </p>
Somehow I can't seem to remove them, I think it has something to do with character settings or something. This is what I've tried:
$html = preg_replace('/<[^\/>]*>([
$html = preg_replace('%<p></p>%','
$html = preg_replace('%<p> </p>%','' , $html);
$html = str_replace('<p> </p>','',$html);
Any suggestions?
ASKER
nope not working
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think you have to escape every less than and greater than and slash.
\<p\>\<\/p\>
\<p\>\<\/p\>
ASKER
Solved the problem :)
$html = preg_replace('\<p>\<\p>','
to remove <p></p>
Ss