View Full Version : Importing/incorporating code from an external web page?

03-17-2009, 03:53 PM

Basic php/html/mysql skills here

I do code for a website, they have sold a page to an advertiser that needs to show material from a daily html newsletter, I initially said it would work on the basis that anyone doing a complex html newsletter daily would be able to also produce a block of code that could act as an include

It now turns out that all the advertiser is able to provide is the html email itself.

I'm still squinting at this project from a long way off but I'd be grateful for a rough idea of how this would be tackled.

The html email has the usual 'email not displaying properly?' so there is a webpage for each newsletter, it uses relative links for the css and images

Is it as simple as my webpage reading their code from their website, and then some manipulation to make their links absolute paths and top and tail out their headers and footer so it can appear within my headers and footers? That said how would I load up actual code from someone else's web page?

Can anyone see problems ahead or suggest any handy dos and don'ts?

Many thanks

03-17-2009, 04:17 PM
googled this, look ok?

$handle = fopen ("http://www.example.com/", "rb");
$contents = "";
do {
$data = fread($handle, 8192);
if (strlen($data) == 0) {
$contents .= $data;
} while(true);
fclose ($handle);

I haven't tested those but from what I saw, $content will be the exact source of the index file in example.com (parts that is shown to the world of course - not the serverside scripts)

so now we can look for some pattern in $content