php 怎么获取网页并且替换

WBOY
Release: 2016-06-13 12:55:41
Original
932 people have browsed it

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); 
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