Preg replace:php Filter Hyperlinks and determine if the text in the link is a URL preg

Source: Internet
Author: User
Tags filter preg return

The sample code is as follows:
$str = ' <a class= "style" href= "http://www.cxybl.com/" target= "_blank" >www.cxybl.com</a> <a href= "http ://www.cxybl.com ">cxybl</a> filter HYPERLINK";
$str = Filter_url ($STR);
The processing code is as follows:
function Filter_url ($STR) {
Return Preg_replace_callback ("/<a[^>]+> (. +?)" <\/a>/i "," Filter_url_callback ", $str);
}
function Filter_url_callback ($matchs) {
$STR = $matchs [1];
if (! $str) return ";
$arr = Array (' www. ', ' http://', '. com ', '. cn ', '. org ', '. Net ', '. CC ');
foreach ($arr as $k => $v) {
if (Stripos ($str, $v)!==false) return ";
}
return $str;
}
If the hyperlink text is a www.cxybl.com URL, it will also be filtered out. But if it's plain text, keep it.

This article links http://www.cxybl.com/html/wlbc/Php/20130602/38225.html

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.