当前位置: 代码迷 >> PHP >> php 怎么获取网页并且替换
  详细解决方案

php 怎么获取网页并且替换

热度:80   发布时间:2013-01-25 15:55:29.0
php 如何获取网页并且替换?
比如 我获取到了百度的源码
<?php 
$url = "http://www.baidu.com"; 
$contents = file_get_contents($url); 
echo $contents; 
?> 


然后我想要的替换里面的连接
比如
href="http://baike.baidu.com" 把http://baike.baidu.com 替换成一个变量 然输出

类似与 href="$newurl"

------解决方案--------------------
$newurl='sohu.com';
echo preg_replace('/href="(.+?)"/i','href="'.$newurl.'"',$contents); 
  相关解决方案