Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2007
    Location
    In front of PC
    Posts
    96
    Thanks
    25
    Thanked 3 Times in 3 Posts

    Smile Expression match help. preg_match

    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.

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

    echo 
    preg_replace($pattern$replace$data); 
    Code:
    $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
    Last edited by tamilsweet; 02-28-2010 at 05:20 AM.
    Learning never ends....

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    $pattern = '#<a[^>]href\s*=\s*"http://google[^>]*><img[^>]*></a>#i';

  • Users who have thanked MattF for this post:

    tamilsweet (02-27-2010)

  • #3
    New Coder
    Join Date
    Oct 2007
    Location
    In front of PC
    Posts
    96
    Thanks
    25
    Thanked 3 Times in 3 Posts
    Thanks a lot. That fixed the issue.
    Learning never ends....


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •