Matt Elhotiby
Matt Elhotiby

Reputation: 44066

Making the money value with only numbers

I just posted this question link text about 5 minutes ago and I forgot to mention that the format was like this

"$2,090.99 "

I need the final value like

"209099"

Striping the final extra space and getting rid of any other punctuation in the money value with php so i can store into a mysql decimal 10,2

Upvotes: 1

Views: 103

Answers (2)

bcosca
bcosca

Reputation: 17555

You might be better off using PHP 5.3's MessageFormatter, Locale and Intl classes if you'll be handling different locales and currency formats. The msgfmt_parse() method might just be what you need.

Upvotes: 6

Gumbo
Gumbo

Reputation: 655489

You can use a regular expression to replace everything that is not a digit:

$output = preg_replace('/\D/', '', $str);

\D is equivalent to [^\d] that is equivalent to [^0-9].

Upvotes: 6

Related Questions