display parts of content from remote webpage

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
jor
Forum Newbie
Posts: 1
Joined: Wed Oct 06, 2004 8:50 am

display parts of content from remote webpage

Post by jor »

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I'm trying to add some content from a remote webpage to my site. I've tried to search for something like this on the forums, but can't really find anything.

Using PHP, how can I simply read some content, for eks. weather info from a remote site (not web service). I have tried out this:

Code: Select all

$fp = fopen("http://somesite.com", "r");
$contents = '';
$contents .= fread($fp, 8192);
echo $contents;
fclose($fp);
This reads 8192 bytes. How do I know the amount I need to read? I really don't want to read the whole page. Is it at all possible to retrieve just parts of another webside, such as weatherinfo? Or do I have to get access to an xml file containing the info I want?

Any suggestions on this would help a lot.
Thanks ;)


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]filesize[/php_man]()

although I'd use [php_man]file_get_contents[/php_man]() instead of fopen.

As far as getting only part, you still have to read most, if not all of it, because the content could be anywhere on the page. I use [php_man]preg_match[/php_man]() and its cousins to extract information from sites..

sidenote: it's advisable to get the permission of the site you are extracting information from to do so.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If the site is happy for you to extract content, and you are going to be extracting information from the same page each time you may be able to find a piece of the HTML that is constant and acts as a signpost for the content you want.

Mac
Post Reply