请好手帮忙写一段正则代码

WBOY
Release: 2016-06-13 12:52:49
Original
982 people have browsed it

请高手帮忙写一段正则代码
通过如下代码获取到网页的内容

<br />
$conn=file_get_contents("http://ygtc.tmall.com");<br />
Copy after login

然后将里面的所有带有http://的网址通过foo()函数处理后,放回原处,最后输出网页
foo()函数如下
<br />
function foo($url)}<br />
//$url为传入的网址<br />
return md5($url);//这里只是简单写了下函数的处理方式,实际上处理方式不是这么简单,只是作为事例;<br />
}<br />
Copy after login


------解决方案--------------------
$conn = file_get_contents("http://ygtc.tmall.com");
echo preg_replace_callback('/(  
function foo($url) {
  return $url[1] . md5($url[2]);//这里只是简单写了下函数的处理方式,实际上处理方式不是这么简单,只是作为事例;
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template