Created
June 8, 2015 09:18
-
-
Save pankamilr/8142b6ee7630dfe2d140 to your computer and use it in GitHub Desktop.
Add rel nofollow to all external links in given content. $skip contains domain name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function nofollow($html, $skip = null) { | |
return preg_replace_callback( | |
"#(<a[^>]+?)>#is", function ($mach) use ($skip) { | |
return ( | |
!($skip && strpos($mach[1], $skip) !== false) && | |
strpos($mach[1], 'rel=') === false | |
) ? $mach[1] . ' rel="nofollow">' : $mach[0]; | |
}, | |
$html | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment