Regular Expression

Posted on 2007-10-20
Last Modified: 2007-10-20
I am trying to do an expression and use preg_replace to remove all urls, except some


Where that would remove all urls except ebay.
but it dosn't replace anything, how can I tell it to 'ignore'
Question by:wildzero
    LVL 20

    Accepted Solution

    try this

    function check_url($matches){
      $url = "";
      $array_ignore = array("",""); // will ignore and ---- add urls here
     $prepare_url = parse_url($matches[1]);
     if($prepare_url["host"]) {
           $url = str_replace("www.","",strtolower($prepare_url["host"]));
           return false;
      if(in_array($url,$array_ignore)) {
            return $matches[0];
            return false;

    echo preg_replace_callback('@<a href="([^"]+)">[^<]+</a>@',"check_url",$string);
    LVL 10

    Author Comment

    Thats working perfect

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now