PHP regular replacement non-station internal chain replacement Zencart description of non-site links

Source: Internet
Author: User

PHP is replacing non-site links

<?PHP//The text to replace, such as the text in the product descriptionHeader("content-type:text/html; Charset=utf-8 "); $content=<li><a href= "http://afish.cnblogs.com" target= "_blank" > Small fish Court </a></li><li><a href= "http://afish.cnblogs.com" target= "_blank" > small fish Court </a></li><li><a href= "http:/ /afish.cnblogs.com "target=" _blank "> small fish Court </a></li><li><a href="/http Www.baidu.com "target=" _blank "> Baidu </a></li><li><a href=" http://www.baidu.com "target=" _ Blank "> Baidu </a></li><li><a href=" http://www.baidu.com "target=" _blank "> Baidu </a>< /li><li><a href= "http://www.soso.com" target= "_blank" > Search </a></li><li><a href= "Http://www.soso.com" target= "_blank" > Search </a></li><li><a href= "http://www.soso.com" target = "_blank" > Search </a></li>‘;//the site domain name$host _url=Str_replace(".", "\.",Str_replace("www.", "",$_server[' Http_host ']));//Echo $host _url;//replacement Regular$pattern= '/<[^>]*href=[\ ' \ ']http?:\ /\/(?!‘.Str_replace("/http", "",$host _url). ' | '.Str_replace("http://www.", "",$host _url). ' | [\w\_]+\.]Str_replace("http://www.", "",$host _url).‘) [^\ ' ^\ ']*[\ ' \ '][^>]*> (. +?) <\/a>/is ';//Replace the content//$replace = ' <a href= ' http://'. $_server[' http_host '. ' target= ' _blank ' >$1</a> ';$replace= ' <a href= ' http://'.$_server[' Http_host ']. ' " target= "_blank" > Site link </a> ';//to replace$content=Preg_replace($pattern,$replace,$content);//output the replaced contentEcho $content;?>

PHP regular replacement non-station internal chain replacement Zencart description of non-site links

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.