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

WBOY
Release: 2016-06-13 11:12:48
Original
1074 people have browsed it

替换源码中获取后的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);
Copy after login
href="http://217"
href="http://562"
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!