Page 1 of 1
remove (some) tags
Posted: Mon Feb 14, 2011 5:47 pm
by pedroz
In the following HTML content
<a href="www.google.com">Google</a>
blah blah blah...
<a href="www.bing.com"><img src="a.gif></a>
How can I remove image links only?
Need to keep others links...
Any ideas? Thanks.
Re: remove (some) tags
Posted: Tue Feb 15, 2011 6:47 am
by pedroz
Almost done. Just need to keep the <img> tag... Any help?
Code: Select all
$str = '<a href="www.google.com">Google</a>
blah blah blah...
<a href="www.bing.com"><img src="a.gif></a>
';
$pattern = '/<a[^>]+><img[^>]+><\/a>/i';
$output = preg_replace($pattern, '', $str);
echo $output;
Re: remove (some) tags
Posted: Tue Feb 15, 2011 7:26 am
by cpetercarter
Your two posts seem to say different things. Which are you trying to do - remove only the image tag; or remove all other tags but keep the image tag?
Re: remove (some) tags
Posted: Tue Feb 15, 2011 10:08 am
by Darhazer
Code: Select all
<?php
$str = '<a href="www.google.com">Google</a>
blah blah blah...
<a href="www.bing.com"><img src="a.gif></a>
';
$pattern = '/<a[^>]+>(<img[^>]+>)<\/a>/i';
$output = preg_replace($pattern, '$1', $str);
echo $output;