[Regular Expression] Add NoFollow Attribute to All Links in String

Discussion in 'PHP' started by ColorWP.com, Apr 23, 2010.

  1. #1
    Hello.

    I have a string called $string and it has a lot of content (including HTML).

    It also contains a lot of links with different attributes (e.g. onclick, href, style, id). How do I add the rel="nofollow" attribute to all these links without breaking them?

    And assign the new content to $string again.

    Regards!
     
    Solved! View solution.
    ColorWP.com, Apr 23, 2010 IP
  2. #2
    why don't you just make this really simple with something like this?

    $string = str_replace('href','rel="nofollow" href',$string);
     
    zadro, May 22, 2010 IP
    www.Andro.ws likes this.