Home >php教程 >PHP源码 >php正则之删除或转换字符串中url地址

php正则之删除或转换字符串中url地址

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:25:071601browse

主要是url操作函数,可以删除字符串的url同时也可以给字符串中的url加连接哦,有需要的朋友参考一下。

<script>ec(2);</script>

删除url

 

 代码如下 复制代码
$string = preg_replace('/b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]/i', '', $string);

将url转换成链接

 

 代码如下 复制代码
$url = "Jean-Baptiste Jung (http://www.111cn.net)";
$url = preg_replace("#http://([A-z0-9./-]+)#", '$0', $url);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn