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. 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+) 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+) 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! 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). 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. 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. 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
Archived
This topic is now archived and is closed to further replies.