-Karl- Posted June 3, 2010 Share Posted June 3, 2010 <?php $cnt = count($item_matches[1]); $display = ""; for ($i=0; $i<$cnt; $i++) { $id_match = array(); preg_match('~([0-9]+)$~', $item_matches[1][$i], $id_match); //Grab minimum and maximum price $cc = curl_init() or die(curl_error()); curl_setopt($cc, CURLOPT_URL,'http://services.runescape.com/m=itemdb_rs/Hi/viewitem.ws?obj=' . $id_match[1]); curl_setopt($cc, CURLOPT_RETURNTRANSFER, 1); $rawr = curl_exec($cc) or die(curl_error()); curl_close($cc); $contenty = str_replace($newlines, "", html_entity_decode($rawr)); preg_match_all('~<b>Minimum price:</b> ([\.\0-9a-zA-Z]+)~',$contenty,$min_matches); preg_match_all('~<b>Maximum price:</b> ([\.\0-9a-zA-Z]+)~',$contenty,$max_matches); $filename = "".$_SERVER{'DOCUMENT_ROOT'}."/purehead/item/images/".$id_match[1].".gif"; if (!file_exists($filename)) { $cd = curl_init(); curl_setopt($cd, CURLOPT_URL, 'http://services.runescape.com/m=itemdb_rs/3012_obj_sprite.gif?id=' . $id_match[1]); curl_setopt($cd, CURLOPT_HEADER, 0); curl_setopt($cd, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cd, CURLOPT_BINARYTRANSFER,1); $rawdata = curl_exec($cd); $contentie = html_entity_decode($rawdata); curl_close($cd); $fp = fopen("images/".$id_match[1].".gif",'w'); fwrite($fp, $rawdata); fclose($fp); } if (strstr($change_matches[2][$i], '+')) { $fontcolor = "green"; } if (strstr($change_matches[2][$i], '-')) { $fontcolor = "red"; } if (!strstr($change_matches[2][$i], '+') && !strstr($change_matches[2][$i], '-')) { $fontcolor = "blue"; } $display .= "ID: " . $id_match[1] . "<br/>"; $display .= "Item: " . $item_matches[2][$i] . "<br/>"; $display .= "URL: " . $item_matches[1][$i] . "<br/>"; $display .= "Minimum Price: " . $min_matches[1][$i] . "<br/>"; $display .= "Market Price: " . $price_matches[1][$i] . "<br/>"; $display .= "Maximum Price: " . $max_matches[1][$i] . "<br/>"; $display .= "Change: <font color=\"".$fontcolor."\">" . $change_matches[2][$i] . "</font><br/>"; $display .= "Image: <img src='images/".$id_match[1].".gif'/><br/><br/>"; } echo $display; ?> There's my code, everything should be working fine, but it isn't and I can't figure it out for the life of me. Anyway, the minimum and maximum price is only displayed for the first result, and it's blank for the following results. Any ideas what's causing it to not loop the cURL for each result it finds? curl_setopt($cc, CURLOPT_URL,'http://services.runescape.com/m=itemdb_rs/Hi/viewitem.ws?obj=' . $id_match[1]); That line should be carried out, for each result that's found, as it grabs more specific information on that item from there. However, it only does it for the first item. EDIT: Array ( [0] => Array ( [0] => Minimum price: 516.8m ) [1] => Array ( [0] => 516.8m ) ) Array ( [0] => Array ( [0] => Minimum price: 368.0m ) [1] => Array ( [0] => 368.0m ) ) Array ( [0] => Array ( [0] => Minimum price: 357.9m ) [1] => Array ( [0] => 357.9m ) ) Array ( [0] => Array ( [0] => Minimum price: 394.5m ) [1] => Array ( [0] => 394.5m ) ) Array ( [0] => Array ( [0] => Minimum price: 428.3m ) [1] => Array ( [0] => 428.3m ) ) Array ( [0] => Array ( [0] => Minimum price: 369.2m ) [1] => Array ( [0] => 369.2m ) ) It's getting the data fine, it's just not displaying it for each result. Link to comment https://forums.phpfreaks.com/topic/203717-curl-and-displaying-data/ Share on other sites More sharing options...
sniperscope Posted June 3, 2010 Share Posted June 3, 2010 Problem solved? Link to comment https://forums.phpfreaks.com/topic/203717-curl-and-displaying-data/#findComment-1067021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.