Grab data from URL

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
bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

Grab data from URL

Post by bladecatcher »

G'day All,
I want to grab data from a public web site parse it and add it to my page (with permission of coarse).

A starting point would be how to grab the page, yes?

Where and what am I looking for?

Thanking you in advance,
bladecatcher
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Start here

Post by neophyte »

hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

i believe it involves several things. you wanted to know the structures of that page in order to find out where on that page you want to get the info from.

some useful functions such as:

file(), explode() etc...
bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

Post by bladecatcher »

G'day,
Thank you for your replies.

file_get_contents looks like what I'm after but ...

Is it a php4 function?

I get:

Fatal error: Call to undefined function: file_get_contents() in /var/www/xxx/weather.php on line 5

tia
bladecatcher
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

file_get_contents
(PHP 4 >= 4.3.0, PHP 5)
you can also try fopen(), fread(),fclose()
bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

Post by bladecatcher »

yep, I saw that.

sorry I should have been more explicite

I'm interpreting that as > PHP 4.3.0 ???

I've found phpinfo.php will run that and see.
bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

phpinfo says

Post by bladecatcher »

damn, PHP Version 4.1.2

Thanks for the start though, I'll look at the longer route.

Any alternative suggestions?

Thanks very much guys

btw, I got the version by running a file phpiinfo.php which I found easily through a google search.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Phenom wrote: you can also try fopen(), fread(),fclose()
...
bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

Post by bladecatcher »

Thanks All,
so far I've got:

Code: Select all

$wpage = fopen("http://www.site.com.au/cgi-bin/script.pl?ID1.txt", "r");

while(!feof($wpage))
{
	$output = fgetss($wpage, 1024);
   	echo ("$output<br />");
}

fclose($wpage);
Now I need to search $wpage for a string (mystring) then output the next 3 lines.

I could use strstr on each line however is there a function to find the first occurance of a string in the file?

tia
bladecatcher
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

strpos

Post by bladecatcher »

Thank you very much.
Post Reply