...

View Full Version : Resolved Expression match help. preg_match



tamilsweet
02-27-2010, 12:53 PM
Hello,
I'm trying to form a expression to search all <a> tags with href as specific site and <img> tag inside.
Here is what I have and it worked in KATE search/replace but not in PHP.


$pattern = '<a[^>]href\s*=\s*"http://google[^>]*><img[^>]*></a>';
$replace = '<!-- -->';

echo preg_replace($pattern, $replace, $data);




$data being the HTML data.
eg.
<div>
<a href="http://google.com/" title=""><img src="http://site.com/image.jpg" width="100" height="50" /></a>
</div>

needs to be replaced by
<div><!-- --></div>

Regards,
Tamil

MattF
02-27-2010, 01:39 PM
$pattern = '#<a[^>]href\s*=\s*"http://google[^>]*><img[^>]*></a>#i';

tamilsweet
02-27-2010, 02:06 PM
Thanks a lot. That fixed the issue.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum