Home >Backend Development >PHP Tutorial > 求好手,关于网址正提取则

求好手,关于网址正提取则

WBOY
WBOYOriginal
2016-06-13 12:36:47845browse

求高手,关于网址正提取则

本帖最后由 dz215136304 于 2013-09-10 14:52:56 编辑 需求:提取出字符串中的url

因为需要将提取出来的网址再次处理,所以放到回调函数里,但是同样的正则放在preg_match_all正常,而放到preg_replace_callback中就不起作用,一下代码是提取出sdfsd.qq.www.qq.com

<br />
<br />
$con='http://sdfsd.qq.www.qq.com/sdf.html?a=c';<br />
//preg_match_all('/([a-z1-9\.]+\.[com|cn|info]+)/is', $con, $arr);<br />
//print_r($arr);这里可以正常提取出sdfsd.qq.www.qq.com的网址<br />
<br />
<br />
$conn=preg_replace_callback('/([a-z1-9\.]+\.[com|cn|info|tk|us]+)/isum', 'url', $con);//同样的正则放到这里就提取不出sdfsd.qq.www.qq.com<br />
echo $conn; <br />
  <br />
function url($url){<br />
return $url[1];//不管这里是$url[0]还是$url[1]<br />
}<br />
<br />
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