StudioTime
StudioTime

Reputation: 23999

preg_replace to include decimal point

I have currency values within a table and for filtering I want to show only the numbers without currency symbols, but, I need the decimal point, here's what i'm using

$price_check = preg_replace('/\D/', '', str_replace(',','',(str_replace('£','',$item[item_price])));

How do I keep the decimal point? is first question

Also, I'm removing £ first (ascii for GBP) and then removing comma (if present) - is there a better way to do this?

Upvotes: 0

Views: 441

Answers (1)

StudioTime
StudioTime

Reputation: 23999

Figured it out, the preg_replace anyway

$price_check = preg_replace('/(\.[0-9]+?)0*$/', '$1', str_replace(',','',(str_replace('£','',$item[item_price]))));

Upvotes: 1

Related Questions