Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function __WrappingTags($html)
- {
- function isExternalLink($link)
- {
- $link = parse_url($link);
- if(isset($link["host"]))
- if($link["host"]=="3data.ru")
- return false;
- else
- return true;
- else
- return false;
- }
- //$html = "Текст <a href='http://yandex.ru/page1.html'>ссылка</a> bbb Текст <a href='http://3data.ru/page1.html'>текст</a> и снова <a href=\"page2.html\" title=''>еще ссылка</a> конец";
- $nofollow = ' target="_blank" rel="nofollow';
- $prefix = "<!--noindex-->";
- $postfix ='<!--/noindex-->';
- preg_match_all("/<[Aa][\s]{1}[^>]*[Hh][Rr][Ee][Ff][^=]*=[ '\"\s]*([^ \"'>\s#]+)[^>]*>/", $html, $matches);
- $changed = $matches[1];
- $toreplace = $matches[1];
- for($i=0; $i<count($changed); $i++)
- if(isExternalLink($changed[$i]))
- $changed[$i] = $changed[$i] . '"' . $nofollow;
- else
- $changed[$i] = $matches[1][$i];
- $html = str_replace($toreplace, $changed, $html);
- preg_match_all("/<[Aa][\s]{1}[^>]*[Hh][Rr][Ee][Ff][^=]*=[ '\"\s]*([^ \"'>\s#]+)[^>]*>/", $html, $matches);
- $change = $matches[0];
- $rep = $matches[0];
- for($i=0; $i<count($change); $i++)
- if(isExternalLink($matches[1][$i]))
- $change[$i] = $prefix . $rep[$i] ;
- else
- $change[$i] = $matches[0][$i];
- $html = str_replace($rep, $change, $html);
- preg_match_all("/<a.+?href[^=]*=[ '\"\s]*([^ \"'>\s#]+)[^>]*>.*?<\/a>/", $html, $new);
- $secondpart = $new[0];
- $replace = $new[0];
- for($i=0; $i<count($secondpart); $i++)
- if(isExternalLink($matches[1][$i]))
- $secondpart[$i] = $secondpart[$i] . $postfix;
- $html = str_replace($replace, $secondpart, $html);
- return $html;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement