资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php如何去除外链

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

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站设计制作、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的三元网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

【相关学习推荐: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编程(视频)


文章标题:php如何去除外链
标题链接:http://cdkjz.cn/article/cggjdi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220