Jump to content

getting certain content from another webpage


smerny

Recommended Posts

I've used get_file_contents() before but it seems like it took a long time to load... what is the best or most efficient way to get certain content from a webpage? Like all the posts on a single forum page for example, without loading any images or styles, just the "source"

Link to comment
Share on other sites

i made this function awhile back... it just seems slow, i guess i'm just curious if theres a faster way

 

function getPrice($n)
{
$ch = curl_init() or die(curl_error());
curl_setopt($ch, CURLOPT_URL,"http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=".$n);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$raw=curl_exec($ch) or die(curl_error());
curl_close($ch);

$findme = 'Item not found';
$pos = strpos($raw, $findme);

if ($pos !== false) {
	return "Item Not Found";
} else {
	$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
	$content = str_replace($newlines, "", html_entity_decode($raw));	

	$start = strpos($content,'<b>Market price:</b> ')+21;
	$end = strpos($content,'</span>',$start);
	$marketValue = substr($content,$start,$end-$start);
	return myStr2Int($marketValue);
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.