Php method for filtering other website links in html (domain name whitelist function) _ PHP Tutorial

Source: Internet
Author: User
Php filters other website links in html (the domain name whitelist function ). The code for copying the code is as follows: *** filter out the origin site link * @ paramarray $ local_domain this site domain name array * @ paramstring $ message text content * functionreplace_outer_links ($ local_do The code is as follows:


/**

* Filter out site links
* @ Param array $ local_domain this site domain name array
* @ Param string $ message text content
*/
Function replace_outer_links ($ local_domain_arr, $ message ){

$ Pattern = '/<[^>] * href = [\' \ "] http [s]? :\/\/(?! ';
$ I = 0;
Foreach ($ local_domain_arr as $ local_domain ){
If ($ I = 0 ){
$ Pattern. = 'www. '. $ local_domain.' | '. $ local_domain.' | [\ w \ _] + \. '. $ local_domain;
} Else {
$ Pattern. = '| www.'. $ local_domain. '|'. $ local_domain. '| [\ w \ _] + \.'. $ local_domain;
}
$ I ++;
}
$ Pattern. = ') [^ \' ^ \ "] * [\ '\"] [^>] *> (. + ?) <\/A>/is ';
Return preg_replace ($ pattern, '$ 1', $ message );
}

The http://www.bkjia.com/PHPjc/760287.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/760287.htmlTechArticle code is as follows:/*** filter out site link * @ param array $ local_domain this site domain name array * @ param string $ message text content */function replace_outer_links ($ local_do...

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.