@NogDogApr 27.2009 — #One way would be to simply replace anything that's not a number with nothing: [code=php] $numbersOnly = preg_replace('#[^0-9]#', '', $valueFromDB); [/code] Another way would be to locate the underscore and take everything after it: [code=php] $numbersOnly = substr($valueFromDB, strpos($valueFromDB, '_') + 1); [/code]
@NogDogApr 27.2009 — #If a character class (the stuff within square brackets) starts with a "^", that means to match on anything that does [b][i]not[/i][/b] match that character class (sort of like the PHP "!" negation operator).
@CharlesApr 27.2009 — #It's likely that you are, just a wee bit, better off using "D" instead of "[^0-9]". They mean the same but one takes less typing. However, regular expressions take enough overhead that they are best avoided when possible. The second above is a better solution.
@NogDogApr 27.2009 — #For the record, there is, in fact, a slight difference between "D" and "[^0-9]", though it likely would not matter for this application: [code=php] <?php $str = ''; for($i=1; $i<=255; $i++) { $str .= chr($i); } echo preg_replace('#D#', '', $str); ?> [/code] Output: