Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove euro sign from string [duplicate]

Tags:

php

currency

I have a php string which contains a currency. In this case it is a € but to make it future proof I would also like to replace other currency's. How can I filter this currency symbol out?

I tried preg replace but don't know the key to filter currency notations out, also I saw a couple of posts in which they did it entirely different, but couldn't manage to get them to work.


Tried your suggestions guys, still doesn't work. If I add a "," to the suggestions below in this post it does remove the , from the price so it does seem to do something. But the € sign remains.

The price is coming from a woocommerce array, and right before I want to remove the € sign I use a "strip_tags" command. Maybe that has to do something with it. If is use a if else statement to see if it is a string it echo's true, so it isn't a float or anything.

like image 386
Spindle Avatar asked Dec 18 '25 13:12

Spindle


1 Answers

If you want to do it quick and easy, just do a string replacement:

$symbols = array('$', '€', '£');
$unformatted = str_replace($symbols, '', $price_string);
like image 194
giorgio Avatar answered Dec 20 '25 03:12

giorgio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!