Home > php教程 > php手册 > body text

preg replace:php过滤超链接并判断链接中文字是否为网址preg_replace_callback函数用法

WBOY
Release: 2016-06-21 08:49:41
Original
1073 people have browsed it

示例代码如下:
$str = 'www.cxybl.com cxybl 过滤超链接';
$str = filter_url($str);
处理代码如下:
function filter_url($str){
return preg_replace_callback("/]+>(.+?)/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;
}
如果超链接的文字为 www.cxybl.com 的网址,也会被过滤掉.但是如果是纯文字的话就保留.

本文链接http://www.cxybl.com/html/wlbc/Php/20130602/38225.html



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template