文件外链PHP,php如何去除外链

php去除外链的方法:将链接加上【rel="nofollow"】属性,代码为【$a['content'] = content_nofollow($a['content'],$domain);】。

5c1d8dfbb33a53a66b27c01d24b5d74d.png

【相关学习推荐:php图文教程】

php去除外链的方法:

解决方法:需要对站点内的内容进行过滤,将不是内部链接的链接加上 rel="nofollow"属性。

本文借鉴了wordpress的过滤外部链接的函数,将其改一下即可使用。

具体代码如下://外部链接增加nofllow $content 内容 $domain 当前网站域名

function content_nofollow($content,$domain){

preg_match_all('/href="(.*?)"/',$content,$matches);

if($matches){

foreach($matches[1] as $val){

if( strpos($val,$domain)===false ) $content=str_replace('href="'.$val.'"', 'href="'.$val.'" rel="external nofollow" ',$content);

}

}

preg_match_all('/src="(.*?)"/',$content,$matches);

if($matches){

foreach($matches[1] as $val){

if( strpos($val,$domain)===false ) $content=str_replace('src="'.$val.'"', 'src="'.$val.'" rel="external nofollow" ',$content);

}

}

return $content;

}

调用的时候很好调用,如下是调用演示$a['content'] = content_nofollow($a['content'],$domain); //将文章内容里的链接增加nofllow属性相关学习推荐:php编程(视频)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值