Remove links

Discussion in 'PHP' started by qayamaat, Aug 16, 2008.

  1. #1
    Hi,

    I'm stuck with this problem (am not too familiar with reg exp).....

    I have to find every href that is not ‘http://www.site1.com/ and remove the href link, but retain the link text.(Example : “<a href="http://www2.comune.roma.it/museociviltaromana/" class="external autonumber" title= "http://www2.comune.roma.it/museociviltaromana/"> humanoid </a>” replace with “ humanoid ”.

    Does anyone know the appropriate regular expression to do that.....?

    Thank you.
     
    qayamaat, Aug 16, 2008 IP
  2. pluswebdev

    pluswebdev Banned

    Messages:
    205
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this
    
    $text = '<a href="http://www2.comune.roma.it/museociviltaromana/" class="external autonumber" title= "http://www2.comune.roma.it/museociviltaromana/"> humanoid </a>';
    
    $patterns[0] = '/<a(.*?)>/si';
    $patterns[1] = '/<\/a>/si';
    $replacements[0] = '';
    $replacements[1] = '';
    echo preg_replace($patterns, $replacements, $text);
    
    
    PHP:
     
    pluswebdev, Aug 16, 2008 IP
  3. qayamaat

    qayamaat Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thnx a lot.....Now, I have to remove all the links that's not 'http://www.site1.com/' from a text file. I'll try to tweak the regex to get it working. :)
     
    qayamaat, Aug 18, 2008 IP