示例代码如下:
$str = '<a class="style" href="http://www.xiaojudeng.com/" target="_blank">www.xiaojudeng.com</a> <a href="http://www.xiaojudeng.com">小桔灯分类信息网</a> 过滤超链接';
$str = filter_url($str);
处理代码如下:
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;
}
如果超链接的文字为 www.xiaojudeng.com 的网址,也会被过滤掉.但是如果是纯文字的话就保留.
分享到:
相关推荐
解决了ecmall php版本升级后,模板编辑,验证码不出来,preg_replace_callback() 函数替换 的方法
本文实例讲述了php中preg_replace_callback函数用法。分享给大家供大家参考,具体如下: mixed preg_replace_callback ( mixed pattern, callback callback, mixed subject [, int limit] ) 本函数的行为几乎和 preg...
本文实例讲述了php正则preg_replace_callback函数的用法。分享给大家供大家参考。具体实现方法如下: php正则表达式功能强大,本范例演示了preg_replace_callback函数的用法 // Define a dummy text, for testing.....
主要介绍了PHP正则替换函数preg_replace和preg_replace_callback使用总结,本文是在写一个模板引擎遇到一个特殊需求时总结而来,需要的朋友可以参考下
我们在这篇文章中将会为大家详细讲解有关PHP函数preg_replace()的相关使用方法。 PHP函数preg_replace()原型:mixed preg_replace (mixed $pattern, mixed $replacement, mixed $subject [, int $limit]) PHP函数...
首先向你介绍下PHP preg_replace,PHP preg_replace的使用是我们实现的方法,那么对于PHP正则表达式替换实现过程我们从实例入手。 PHP正则表达式替换的相关概念: preg_replace:执行正则表达式的搜索和替换 mixed...
preg_replace函数原型: mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit]) 特别说明: /e 修正符使 preg_replace() 将 replacement 参数当作 PHP 代码(在适当的逆向引用替换...
介绍:preg_replace 执行正则表达式的搜索和替换,如果只是单纯的匹配字符串建议使用str_replace(),因为其执行效率高的多。mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit]) ...
在php5.3环境下运行,常常会出现 ...不支持ereg_replace()函数,而使用preg_replace()函数。 解决方法:将不支持的函数修改为支持的函数即可。 例如 复制代码 代码如下: if(eregi(‘^(‘value’, $val
事情的起因是下午遇到了 preg_replace 函数,我们都知道 preg_replace 函数可能会导致命令执行。现在我们来一些情况。 0x02 经过 踩坑1: 测试代码大概是这样的: foreach ($_GET as $regex => $value) { preg_...
eregi_replace与preg_replace 函数代码的用法比较
function ubb($Text) { $Text=htmlspecialchars($Text);... $Text=preg_replace(“/\\t/is”,” “,$Text); $Text=preg_replace(“/\[h1\](.+?)\[\/h1\]/is”,”<h1>\\1”,$Text); $Text=preg_repla
本节我们就来介绍一下PHP中基于perl的正则表达式处理函数,主要包含了分割, 匹配,查找,替换等等处理操作,依旧是配合示例讲解,让我们开始吧。 和正则表达式一样,正则表达式处理函数不能够独立使用,而这必须相...
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in……. 注意:不是所有人的ECSHOP都会报这个错误,只有使用PHP5.5环境的ECSHOP才会报这个错误。 下面ecshop开发...
php正则之函数 preg_replace()参数说明