我正在使用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/
但它不工作更換。任何線索?
我刪除了我的答案,因爲如果執行會有一噸與它的問題。 – 2009-08-01 05:58:29