2009-08-01 124 views
0

我正在使用file_get_contents抓取一个页面,但我需要在回显页面内容之前替换一些数据。使用str_replace和file_get_contents

我有这个迄今为止(这个脚本在运行domain2.com)

<?php 
$page = file_get_contents('http://domain.com/page.html'); 
str_replace('href="/','href="http://domain.com','$page'); 
echo $page; 
?> 

的问题是,当页面显示,该domain.com页面上的一些链接阅读:

<a href=/about.html> 

当我在我的脚本中调用时,正在将它添加到不正确的域。我试着用str_replace函数,寻找

href="/ 

href="http://www.domain.com/ 

但它不工作更换。任何线索?

+0

我删除了我的答案,因为如果执行会有一吨与它的问题。 – 2009-08-01 05:58:29

回答

3

固定它

$pagefixed = str_replace("href=\"/","href=\"http://www.domain.com/","$page"); 

感谢所有

2

由于引号不同,您将需要使用正则表达式(preg_replace)或2 str_replaces。