I want to add rel="nofollow" in all links in my website if the links link to other website.
For example,
$str = "<a href='www.linktoothersite.com'>I swear this isn't spam!</a><br><a href='www.mywebsite.com'>Hello World</a>";
The output should be
$str = "<a href='www.linktoothersite.com' rel="nofollow">I swear this isn't spam!</a><br><a href='www.mywebsite.com'>Hello World</a>";
I really want to regular expression but not DDOMDocument. Because when I using DOMDocument I always got error " Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity"