当前位置:Gxlcms > PHP教程 > 替换源码中获取后的URL的有关问题

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

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

替换源码中获取后的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
href="http://www.baidu.com"
href="http://www.163.com"
TXT;

echo preg_replace('/href="(.+?)"/ise', '"href=\"http://".rand(100,999)."\""',$contents);
href="http://217"
href="http://562"

人气教程排行