dzhax Posted October 5, 2010 Share Posted October 5, 2010 I am working on a project and i am trying to clean up my code so i can release it and not have people leach my code.I have the basic functionality down but, when i put the code into a function it returns nothing...The working code: <? $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=" . $_GET['obj']); curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($curl, CURLOPT_TIMEOUT, 6); $fullge = curl_exec($curl); $lines = explode("\n", $fullge); $minLine = preg_grep("/Minimum price:<\/b> /", $lines); foreach ($minLine as $pNum){$pVal = preg_split('/ /', $pNum, -1, PREG_SPLIT_OFFSET_CAPTURE);} $minPrice = $pVal[2][0]; $medLine = preg_grep("/Market price:<\/b> /", $lines); foreach ($medLine as $pNum){$pVal = preg_split('/ /', $pNum, -1, PREG_SPLIT_OFFSET_CAPTURE);} $medPrice = $pVal[2][0]; $maxLine = preg_grep("/Maximum price:<\/b> /", $lines); foreach ($maxLine as $pNum){$pVal = preg_split('/ /', $pNum, -1, PREG_SPLIT_OFFSET_CAPTURE);} $maxPrice = $pVal[2][0]; $itemName = $lines[228];?> now if i wrap this code with function itemInfo($itemId, $info) { } it stops returing any info.basically i want it so i can just call itemInfo(327,maxPrice); and it prints the $maxPrice on the page.this code in the code tags above will be hosted as a seperate file on my server and the page requesting will be on a remote server. So I'm thinking an include of the function page will be needed correct?EDIT:or possibly just itemInfo(); and then call the $maxPrice in the remote code... or will that not work? Link to comment Share on other sites More sharing options...
wirehopper Posted October 5, 2010 Share Posted October 5, 2010 It's probably a variable scope issue.If you have a variable set outside the function, you have to use 'global' to access it from within the function. $a=5;function f(){echo $a; /* Will cause an error, because $a isn't defined within the function */}function g(){global $a;echo $a; /* Will be okay and the value will be echoed */} Also, check the error log or turn error reporting on. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.