Home  >  Article  >  Backend Development  >  替换源码中获取后的URL的有关问题

替换源码中获取后的URL的有关问题

WBOY
WBOYOriginal
2016-06-13 12:55:101067browse

替换源码中获取后的URL的问题!
$url = "http://www.baidu.com";
$newurl = "http://www.163.com";

$contents = file_get_contents($url);
echo preg_replace('/href="(.+?)"/i','href="http://'.rand(100,999).'"',$contents);

我原本是想把源码中的连接都随机不同替换, 现在就是所有的连接都替换成了一个随机! 请问怎么解决?


------解决方案--------------------
$contents = <<< TXT<br />
href="http://www.baidu.com"<br />
href="http://www.163.com"<br />
TXT;<br />
<br />
echo preg_replace('/href="(.+?)"/ise', '"href=\"http://".rand(100,999)."\""',$contents);
href="http://217"
href="http://562"
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