0

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?

1
  • I deleted my answer because there would be a ton of problems with it if executed. Commented Aug 1, 2009 at 5:58

2 Answers 2

3

fixed it

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

Thanks all

Sign up to request clarification or add additional context in comments.

Comments

2

You'll either need to use a regular expression (preg_replace) or 2 str_replaces since quotes vary.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.