There are several ways to include information from another website into my website.

One of the easiest ways is using the iframe tag:

<iframe src="https://cindycullen.com">
  Your browser doesn't like iframes
</iframe>

The iframe tag will pull in the page and show it exactly like it would show that page in my browser window. It basically makes my webpage a wrapper for the page that is ‘iframed’ in. There are several attributes for the iframe tag that will allow me to adjust width, height, borders, scrolling and more.

The iframe tag works well if I want to pull another HTML page into mine, but if I want to manipulate the data from the other webpage, iframe isn’t going to help me very much. For instance, if the other page is an rss feed or an xml feed of some kind, using iframe is just going to pull the data into my page, but doesn’t really give me access to that data.

One of the easiest ways to access the data from the other web page is using the PHP function file_get_contents:

$mystring = file_get_contents("http://cindycullen.com")

This will return the code for the entire webpage into a string. Then I can parse the string and do whatever I want with the data. This works especially well for xml feeds so that I can parse the xml.

If you try this and it doesn’t work for you, it could be that your hosting provider doesn’t allow you to use this function. You can check to see if they allow it like this:

if (ini_get('allow_url_fopen')) {
  echo 'file_get_contents is allowed on this server';
} else {
  echo 'file_get_contents is not allowed on this server';
}

If it doesn’t work for you, there are other ways to pull information from another website such as cURL and sockets, but those are posts for another day.

Leave a Comment

Your email address will not be published. Required fields are marked *