papaface Posted December 13, 2006 Share Posted December 13, 2006 Hello,I was wondering if someone can show me how (or point me in the right direction) I would:[code]$file = file_get_contents("someurl.com")or die ("error " . mysql_error());echo $file;[/code]^^ use that code, and then ask php to find a particular phrase in the contents of the url, for instance: "Item price: $21" and then echo it out to the browser.Note: the value of item total would change quite frequently, so i need a way of getting "Item price: something".Thanks. Quote Link to comment Share on other sites More sharing options...
papaface Posted December 13, 2006 Author Share Posted December 13, 2006 Anyone please? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 13, 2006 Share Posted December 13, 2006 Untested:[code]<?phppreg_match_all("~^Item price: \$[0-9]~", $file,$out, PREG_PATTERN_ORDER);foreach($out as $value){ echo $value.'<br>';}?>[/code] Quote Link to comment Share on other sites More sharing options...
papaface Posted December 13, 2006 Author Share Posted December 13, 2006 Thanks, but I get "Array" when using:[code]<?php$file = file_get_contents("someurl.com")or die ("error " . mysql_error());echo $file;preg_match_all("~^Item Price: \$[0-9]~", $file,$out, PREG_PATTERN_ORDER);foreach($out as $value){ echo $value.'<br>';}[/code] Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 13, 2006 Share Posted December 13, 2006 Try this:[code]<?php$file = file_get_contents("someurl.com")or die ("error " . mysql_error());echo $file;preg_match_all("~^Item Price: \$[0-9]~", $file,$out, PREG_PATTERN_ORDER);foreach($out[1] as $value){ echo $value.'<br>';}[/code] Quote Link to comment Share on other sites More sharing options...
papaface Posted December 13, 2006 Author Share Posted December 13, 2006 I get:Warning: Invalid argument supplied for foreach() in xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx on line 6 Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 13, 2006 Share Posted December 13, 2006 Try this, and if it doesn't work, than can you show the code that is in the file your retrieving? [CODE]<?php$file = file_get_contents("someurl.com")or die ("error " . mysql_error());echo $file;preg_match_all("~^[a-zA-Z]: \$[0-9]$/i~", $file,$out, PREG_PATTERN_ORDER);foreach($out[0] as $value){ echo $value.'<br>';}[/CODE] Quote Link to comment Share on other sites More sharing options...
papaface Posted December 13, 2006 Author Share Posted December 13, 2006 [code]<?php$file = file_get_contents("http://www.amazon.co.uk/Sony-Ericsson-W800i-Vodafone-Weekends/dp/B000BSRU6I")or die ("error " . mysql_error());echo $file;preg_match_all("~^Price: \£[0-9]$/i~", $file,$out, PREG_PATTERN_ORDER);foreach($out[0] as $value){ echo $value.'<br>';}?>[/code]That is what im using. Its not the URL im really trying to use, but it still doesnt work. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 13, 2006 Share Posted December 13, 2006 I almost have it. Sorry for the wait. Quote Link to comment Share on other sites More sharing options...
papaface Posted December 13, 2006 Author Share Posted December 13, 2006 No problem :) Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 13, 2006 Share Posted December 13, 2006 I am so close, I am able to have it get this:Price: £159: 9But I need to get this:Price: £159.99 Quote Link to comment Share on other sites More sharing options...
papaface Posted December 13, 2006 Author Share Posted December 13, 2006 Great :) Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 13, 2006 Share Posted December 13, 2006 This is the best I could come up with:[code]<?php$url = "http://www.amazon.co.uk/Sony-Ericsson-W800i-Vodafone-Weekends/dp/B000BSRU6I";$html = file_get_contents(trim($url));$match = explode("<b>",$html);echo $match[1];?> [/code] Quote Link to comment Share on other sites More sharing options...
papaface Posted December 13, 2006 Author Share Posted December 13, 2006 Its good for that website. But as I mentioned the link I gave you isnt the link I want to use. The link I want to use is for something completely different. I basically need the ability to enter a phrase and for php to bring back the phrase then the number to the right of it, whether it be a currency or just a number. Do you have any other method of contact besides the forum The Little Guy ? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 13, 2006 Share Posted December 13, 2006 AIM, or MSNAIM:verve20MSN:alittlecaptin@hotmail.com Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.