Get text from another website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Tubby
Forum Commoner
Posts: 28
Joined: Thu Oct 17, 2002 5:55 pm

Get text from another website

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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 ;)
User avatar
Tubby
Forum Commoner
Posts: 28
Joined: Thu Oct 17, 2002 5:55 pm

Post by Tubby »

Thanks for that, very useful :)
User avatar
emperor
Forum Newbie
Posts: 16
Joined: Tue Mar 02, 2004 11:20 am
Location: UK

Post 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).
Post Reply