mangosaft
mangosaft

Reputation: 31

Include with str_replace function?

I want to create a page with include function. This page should to grab another site and can change text or code with this function str_replace. I hope that it would be possible. I have written this code, but unfortunately it does not work:

<?php
$text = include('http://www.example.com/index.html');
$text = str_replace("<div id=\"hercss\">Hello.</div>", "<div id=\"mycss\">Welcome!</div>", $text);
echo $text;
?>

Maybe you have a solution? It would be fully appreciated by you.

Upvotes: 0

Views: 603

Answers (1)

Adam
Adam

Reputation: 1975

Try this:

<?php
$url = "http://www.example.com/index.html";
$text = file_get_contents($url);

$text = str_replace("<div id=\"hercss\">Hello.</div>", "<div id=\"mycss\">Welcome!</div>", $text);
echo $text;
?>

Include only works with relative links I believe? The function file_get_contents works across domains

Upvotes: 3

Related Questions