preg_replace problem

Discussion in 'Programming' started by bumbar, Dec 12, 2012.

  1. #1
    Hello!
    I have a small problem with preg_replace();

    Here is the code:
    
    $patterns = array();
    $patterns[0] = '/href="http:\/\//';
    $patterns[1] = '/href="https:\/\//';
    $patterns[2] = '/href="http:\/\/www.specialsite.com/';  // without 'rel="nofollow"'
    
    $replacements = array();
    $replacements[0] = 'rel="nofollow" href="http://';
    $replacements[1] = 'rel="nofollow" href="https://';
    $replacements[2] = 'href="http://www.specialsite.com';   // without 'rel="nofollow"'
    
    $content = preg_replace($patterns, $replacements, $content);	
    
    PHP:
    The problem is that everywhere is added 'rel="nofollow'.
    I want where script which meet 'href="http://www.specialsite.com' NOT ADDED rel="nofollow

    And i get bad result:
    
    <a [B]rel="nofollow"[/B] href="http://www.specialsite.com/>....</a>
    <a rel="nofollow" href="http://www.other.com/>....</a>
    <a rel="nofollow" href="https://www.boicho.com">....</a>
    
    HTML:
    Thank you!
     
    Last edited: Dec 12, 2012
    bumbar, Dec 12, 2012 IP