Jeffro Posted August 22, 2011 Share Posted August 22, 2011 okay.. regex is still the hardest thing for me to get, so hoping someone can help with this one. Can I search my $description, grab the dollar sign and all characters immediately following ...until the next space... and store that as $price ? I'm not using commas or decimal points in $price, so only searching for whole numbers.. though these might be any number of characters ($5, $50, $50000). Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/245439-how-might-i-pull-this-price-out-of-description/ Share on other sites More sharing options...
requinix Posted August 22, 2011 Share Posted August 22, 2011 Sure. \$(\d+) Quote Link to comment https://forums.phpfreaks.com/topic/245439-how-might-i-pull-this-price-out-of-description/#findComment-1260630 Share on other sites More sharing options...
Jeffro Posted August 22, 2011 Author Share Posted August 22, 2011 Sure. \$(\d+) Not working for me. Getting: No ending delimiter '$' found in /home/... I also tried /\\$(/\d+) and /\$(/\d+) Quote Link to comment https://forums.phpfreaks.com/topic/245439-how-might-i-pull-this-price-out-of-description/#findComment-1260635 Share on other sites More sharing options...
Jeffro Posted August 22, 2011 Author Share Posted August 22, 2011 I'm all good. I found some code on a different site that worked great. /(\$[0-9,]+(\.[0-9]{2})?)/ Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/245439-how-might-i-pull-this-price-out-of-description/#findComment-1260641 Share on other sites More sharing options...
requinix Posted August 22, 2011 Share Posted August 22, 2011 Too much trouble to learn it, eh? '/\$(\d+)/' Before I gave you the expression, not the PHP string for preg_match() (which apparently you're using, as opposed to MySQL or ereg() or something else). Quote Link to comment https://forums.phpfreaks.com/topic/245439-how-might-i-pull-this-price-out-of-description/#findComment-1260652 Share on other sites More sharing options...
Jeffro Posted August 22, 2011 Author Share Posted August 22, 2011 Too much trouble to learn it, eh? '/\$(\d+)/' Before I gave you the expression, not the PHP string for preg_match() (which apparently you're using, as opposed to MySQL or ereg() or something else). So how would I have use what you gave me? Just a bit confused and trying to understand. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/245439-how-might-i-pull-this-price-out-of-description/#findComment-1260719 Share on other sites More sharing options...
requinix Posted August 22, 2011 Share Posted August 22, 2011 preg_match('/\$(\d+)/', $string, $matches) From there it depends. Quote Link to comment https://forums.phpfreaks.com/topic/245439-how-might-i-pull-this-price-out-of-description/#findComment-1260722 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.