PHP Filter External links and external images add rel="nofollow" Properties _php Tutorial

Source: Internet
Author: User
The original station a lot of articles are excerpts of the external article, the article many links are either time has expired, or is some of the test URL, such as: http://localhost/, such as, link more words, the formation of a lot of dead links, this SEO optimization is very unfavorable. Then you need to filter the content within the site and add the rel= "nofollow" attribute to the link that is not an internal link.

The web found the WordPress filter external link function, change it can be used

External links Add nofllow $content content $domain current site domain function content_nofollow ($content, $domain) {preg_match_all ('/href= ' (. *) ") /', $content, $matches); if ($matches) {foreach ($matches [1] as $val) {if (Strpos ($val, $domain) ===false) $content =str_replace (' href= "'. $val. '" , ' href= '. $val. ' "rel=" external nofollow "', $content); }} preg_match_all ('/src= ' (. *?) ") /', $content, $matches); if ($matches) {foreach ($matches [1] as $val) {if (Strpos ($val, $domain) ===false) $content =str_replace (' src= "'. $val. '", ' src= '. $val. ' "rel=" external nofollow "', $content); }} return $content;} Called when the call is good, the following is a call to the demo $a [' content '] = content_nofollow ($a [' content '], $domain); Add nofllow attributes to the link in the article Content note! Filter the domain name needs to be without "/", such as http://www.ledaokj.com so that can be very good filtering. Text link: Increase the filtering of external links to site content

http://www.bkjia.com/PHPjc/764698.html www.bkjia.com true http://www.bkjia.com/PHPjc/764698.html techarticle The original station many articles are excerpts of the external article, the article many links are either time has expired, or is some of the test URL, such as: http://localhost/, such as, link ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.