Reputation: 10117
I am using file_get_contents to grab a page, but i need to replace some data in the contents of the page before echoing it.
I have this so far (this script runs on domain2.com)
<?php
$page = file_get_contents('http://domain.com/page.html');
str_replace('href="/','href="http://domain.com','$page');
echo $page;
?>
The problem is, that when the page displays, some links on the domain.com page read:
<a href=/about.html>
Which when i call in my script, are prepending it with the incorrect domain. I tried using str_replace, to look for
href="/
and replace it with
href="http://www.domain.com/
But its not working. Any clues?
Upvotes: 0
Views: 2510
Reputation: 10117
fixed it
$pagefixed = str_replace("href=\"/","href=\"http://www.domain.com/","$page");
Thanks all
Upvotes: 3
Reputation: 1319
You'll either need to use a regular expression (preg_replace) or 2 str_replaces since quotes vary.
Upvotes: 2