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. Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/ Share on other sites More sharing options...
papaface Posted December 13, 2006 Author Share Posted December 13, 2006 Anyone please? Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140418 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] Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140423 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] Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140427 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] Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140429 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 Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140432 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] Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140436 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. Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140444 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. Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140465 Share on other sites More sharing options...
papaface Posted December 13, 2006 Author Share Posted December 13, 2006 No problem :) Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140476 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 Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140518 Share on other sites More sharing options...
papaface Posted December 13, 2006 Author Share Posted December 13, 2006 Great :) Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140534 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] Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140551 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 ? Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140553 Share on other sites More sharing options...
The Little Guy Posted December 13, 2006 Share Posted December 13, 2006 AIM, or MSNAIM:verve20MSN:[email protected] Link to comment https://forums.phpfreaks.com/topic/30499-finding-a-phrase/#findComment-140556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.