zimsabre Posted January 21, 2010 Share Posted January 21, 2010 Hello eveyone, i tryed making a script that would find a figure on a certain website, then print it on mine. Here is the script.. <?php //Just change the item name inside the "" to change what item to price check!!! $item = strtolower("blue dragon scale"); $itemfixed = str_replace( " ", "+", $item ); function parseString( $start, $end, $string ) { $before = explode( $start, $string ); $return = explode( $end, $before[1] ); return $return[0]; } $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, 'http://services.runescape.com/m=itemdb_rs/results.ws?query='.$item ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); $contents = strtolower( curl_exec ( $ch ) ); curl_close ( $ch ); $price = parseString( "$item</a></td>\n<td>", "</td>", $contents ); echo "".$price."Gp"; ?> and to bring the item price up on my page i would use <?php require('../prices/bluedragscalesprice.php'); ?> But for every item im checking id use a new .php of the script with a different item name saved. Can i just have one script with a different input method on my web page? Thanks Zimsabre. Link to comment https://forums.phpfreaks.com/topic/189333-can-this-be-simplified/ Share on other sites More sharing options...
Mchl Posted January 21, 2010 Share Posted January 21, 2010 function parseString( $start, $end, $string ) { $before = explode( $start, $string ); $return = explode( $end, $before[1] ); return $return[0]; } function checkPrice($itemName) { $item = strtolower("blue dragon scale"); $itemfixed = str_replace( " ", "+", $item ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, 'http://services.runescape.com/m=itemdb_rs/results.ws?query='.$item ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); $contents = strtolower( curl_exec ( $ch ) ); curl_close ( $ch ); $price = parseString( "$item</a></td>\n<td>", "</td>", $contents ); return $price } echo checkPrice('blue dragon scale').'Gp'; Link to comment https://forums.phpfreaks.com/topic/189333-can-this-be-simplified/#findComment-999462 Share on other sites More sharing options...
zimsabre Posted January 21, 2010 Author Share Posted January 21, 2010 wouldent i still need multiple .php scripts saved with that edit? what im trying to do is edit the script so it can check many different item prices, then print the requested ones on my web page. Link to comment https://forums.phpfreaks.com/topic/189333-can-this-be-simplified/#findComment-999471 Share on other sites More sharing options...
Mchl Posted January 21, 2010 Share Posted January 21, 2010 No you can just move both functions to a separate file, and include them when needed. You can use them like this: require('checkprice.php'); echo 'Blue Dragon Scale: '.checkPrice('blue dragon scale').'Gp'; echo 'Red Dragon Scale: '.checkPrice('red dragon scale').'Gp'; echo '10 x Blue Dragon Scale: '.(10 * checkPrice('blue dragon scale')).'Gp'; Link to comment https://forums.phpfreaks.com/topic/189333-can-this-be-simplified/#findComment-999479 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.