|","",$content)】;2、清除包含指定关键词的超链接。php去除超链接的方法:清除掉一段html文本内容中的超">
当前位置:Gxlcms > PHP教程 > php如何去除超链接

php如何去除超链接

时间:2021-07-01 10:21:17 帮助过:38人阅读

php去除超链接的方法:1、删除html文本内容中的超链接,代码为【ereg_replace("]*>|<\ a="">","",$content)】;2、清除包含指定关键词的超链接。

php去除超链接的方法:

清除掉一段html文本内容中的超链接最常见的写法可以如下:

代码如下:

  1. $str=preg_replace("/<a[^>]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$content);

相关学习推荐:php编程(视频)

1、删除html文本内容中的超链接

代码如下:

  1. ereg_replace("<a [^>]*>|<\/a>","",$content);

2、清除包含指定关键词的超链接

  1. $find="this string is my find";
  2. $string='<font color="red">这段内容将要被替换掉</font>';//将超链接替换成的内容
  3. echo ereg_replace('<a([^>]*)>([^<]*'.$find.'[^>]*)</a>','<font color="red">\\2</font>',$content);

下面同时分享几种获取html文本内容中的超链接的文本内容方法:

  1. //方法一
  2. preg_match_all('/<(a|a)[s]{0,1}[w=":()]*>[nrn]*(check user)[nrn]*</(a|a)>/i',$string,$matches);
  3. //方法二
  4. preg_match_all('/<a[dd]*>check user</a>/i',$string,$matches);
  5. print_r($matches);
  6. //方法三
  7. preg_match_all('/<a[^>]*>[^<]*</a>/i',$string,$matches);
  8. print_r($matches);
  9. //方法四
  10. preg_match_all('/<a.+?>check user</a>/is',$str,$arr);
  11. print_r($arr);

相关推荐:编程视频课程

以上就是php如何去除超链接的详细内容,更多请关注gxlcms其它相关文章!

人气教程排行