Categories

Archives

Syndication


External content in DIV

4
Oct
Posted in Internet, PHP

Ever thought of having external content in a DIV without using iframes?

Iframes are ugly and will not validate properly in strict XHTML so therefore a solution for this is needed.
The solution we will use is a very simple PHP function that will grab the content from the page and then display it properly.

So how do we replace that iframe with something else? How can we create an iframe without an iframe?

This solution is widely used as proxy-scripts around the web and it is by far the most simple.

If you’re only aiming to replace an iframe you can do it easily with the file_get_content PHP function.

1
2
3
4
5
6
7
<?php
function displaycontent($url)
{
$content = file_get_content($url);
echo $content;
}
?>

And if you are aiming for a simple proxy-script, you can just add a str_replace command and replace all hrefs with some additional characters:

1
2
3
4
5
function displaycontentproxy($url)
{
$content = file_get_content($url);
$content = str_replace('href="', 'href='proxy.php?url=', $content);
}

A very simple solution to the iframe problem. Solved?

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Technorati
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Furl
  • Netscape
  • De.lirio.us
4:49 am on December 3rd, 2008
ooopinionsss

How you think when the economic crisis will end? I wish to make statistics of independent opinions!

Leave us a comment