bbbb标签为 ‘去除链接’
方法二三较为简单.推荐
问题提问地址: www.phpchina.com/bbs/thread-91930-1-1.html
方法一:
<?php
/**
* 替换非指定的链接
*
* @param string $str // 要过滤的文本
* @param string $top_level_domain // 一级域名,但不包含www 如[url=http://www.google.com]http://www.google.com[/url] 输入google.com
* @return string $str
*/
function replace_not_appoint_url($text, $top_level_domain) {
$top_level_domain_regex = str_replace(‘.’, ‘\.’, $top_level_domain);
//$parten1 = ‘/<a(.*?)href=(”|\’)?http:\/\/(.*?)\.?google\.com\/?(.*?)(”|\’)?(.*?)>(.+?)<\/a>/i’;
$parten1 = ‘/<a(.*?)href=(”|\’)?http:\/\/(.*?)\.?’.$top_level_domain_regex.‘\/?(.*?)(”|\’)?(.*?)>(.*?)<\/a>/i’;
//$parten2 = ‘<a\\1#Mref#=”http://\\3.google.com/\\4″\\5>\\6</a>’;
$parten2 = ‘<a\\1#Mref#=\\2http://\\3.’.$top_level_domain.‘/\\4\\5\\6>\\7</a>’;
$parten3= ‘/<a.*?href.*?>(.*?)<\/a>/i’;
$text = preg_replace($parten1, $parten2, $text);
$text = preg_replace($parten3, ‘\\1′, $text);
$text = [...]












