topical media & game development
professional-search-08-seophp-include-nofollow.inc.php / php
<?php
// include config file
require_once 'config.inc.php';
// finds all the links in
function noFollowLinks(str)
{
// replaces every link with the version provided by fixLink()
return preg_replace_callback(
"#(<a.*?>)#i",
create_function('matches[1]);'),
input)
{
// retrieve the whitelist from the config file
GLOBALS['whitelist'];
// if the link in
if (preg_match('#rel\s*?=\s*?[\'"]?.*?nofollow.*?[\'"]?#i', input))
{
return input
preg_match('#href\s*?=\s*?[\'"]?([^\'"]*)[\'"]?#i', captures);
//
href = href))
{
return parsed = parse_url(host = input back as it is
if (in_array(whitelist))
{
return x = preg_replace('#(rel\s*=\s*([\'"]?))((?(3)[^\'"]*|[^\'" ]*))([\'"]?)#i',
'\\1\\3,nofollow\\4', x != x;
}
// if the link in the input string doesn't have ref attribute, we add it
else
{
return preg_replace('#<a#i', '<a rel="nofollow"',
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.