蚂蚁商户发布文章、商品是可以添加外链或者直接用外部图片,但是这对分类网站运营不利。 所以要对外链进行过滤,演示网站,蚂蚁分类的源码。
1、添加过滤外链函数
打开/include/global.php 添加处理函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | function tsNofollow( $content , $domain = "https://www.0516fangchan.com" ){
preg_match_all( '/href="(.*?)"/' , $content , $matches );
if ( $matches ){
foreach ( $matches
as $val ){
if
strpos ( $val , $domain
$content = str_replace ( 'href="' . $val . '"'
'href="' . $val .
, $content );
}
}
preg_match_all( '/src="(.*?)"/' , $content , $matches );
if ( $matches ){
foreach ( $matches
as $val ){
if
strpos ( $val , $domain
$content = str_replace ( 'src="' . $val . '"'
'src="' . $val .
, $content );
}
}
return $content ; } |
*$domain 是不用过滤的域名,全部过滤就不用给默认值
2、发布文章调用处理函数
打开/member/include/inc_document.php查找$content = isset($_POST['content'])在后面添加
1 | $content
stripslashes ( $content )); |
*注意必须要加stripslashes先处理文章的转义字符
这样就处理完毕了,商品也是类似处理。