Page 1 of 1

Get text from another website

Posted: Wed Nov 03, 2004 7:22 am
by Tubby
Hi,
I want to get 2 items of text from another website (with permission from the owner) and save them into a database on my server.
I'd like to know the best way (possibly give examples?) of getting the 2 text items...

The 2 items I want are as follows (everything is always the same apart from the 'number_here', which is the part I want):

<a href="/d/graph120.html" class="menu">number_here</a>
and
<a href="/d/graph132.html" class="menu">number_here</a>

I just want the number_here parts put into 2 variables $grab1 and $grab2, and not the rest.

Any assistance would be great.

Posted: Wed Nov 03, 2004 8:32 am
by timvw
use [php_man]curl[/php_man] to fetch the page, and use [php_man]preg_match[/php_man] to match whatever you need.

If you don't know how to write correct regular expressions, you can always exercise at http://www.samuelfullman.com/team/php/t ... ster_p.php

I think this is more valuable than pre-chewing the answer for you ;)

Posted: Wed Nov 03, 2004 9:02 am
by Tubby
Thanks for that, very useful :)

Posted: Thu Nov 04, 2004 8:11 am
by emperor
Perhaps a slightly easier alternative to using curl to get the contents of a page is [php_man]file_get_contents[/php_man] which works as long as allow_url_fopen is set to "on" in php.ini (which it is by default).