Retrieving Information from another website


Ok, odds are pretty good there is a tutorial out there that will teach me this, but every search I am doing seems to be coming up blank. I am guessing I just do not know the correct terminology.

Ok, for instance (though this is not the specific case). Say I wanted to create a webpage, but when the page is loaded I want it to retrieve some specific information from another page.
I load my page, and say it is about water; and then so it loads from Wikipedia and this page:
But just the CAS number.

Is there an easy way to do that? What would that be called? Perhaps a tutorial? I hope my terminology is correct.

I’m thinking you’ll want to try fsockopen(). Not sure if Wiki will allow such a thing though :confused:
After that, you’re gonna have to do some text parsing magic to filter out the information you want to show on the page.

You will need to fetch the site and load it to variable, which can be done by using fsockopen (or other functions that use fscokopen or fopen), then you will need to parse the content either (this is “easiest”) by using regular expression or some other technique like XSLT parsing.

This worked for me for this specific case:

<?php $url = ''; $x = file_get_contents($url); preg_match('/<td bgcolor="">([[0-9]{4}-[0-9]{2}-[0-9]])</td>/', $x, $match); echo $match[0]; // outpus is: [7732-18-5] ?>

Sponsor our Newsletter | Privacy Policy | Terms of Service