Jump to content

Importing an external page to extract information out of it


pdedecker

Recommended Posts

I want to import an external page somewhere on the internet so that I can extract information out of it. For example: I want to display the current Firefox version number. If I'd like to do that I'd have to import the page HTML into a string, trim the page to get the right information and then echo() it. The thing is, I don't know if and how it's possible to do that using PHP code. Can somebody help me out?

Link to comment
Share on other sites

It's done like this

<?php //get download page of firefox website$page=file_get_contents("http://www.mozilla.org/download.html");//find the position of the below string on the page and add the length of the string$start=strpos($page,'<dt><a href="http://www.mozilla.com/firefox/">Firefox ')+54;//echo the next 7 characters after the position of the above stringecho 'The latest FireFox version is '.substr($page,$start,7);?>

you can see the output herethe problem is if mozzilla changed their page it might stop working.If theres anything in my code you dont understand just ask.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...