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"

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);
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.