I want to parse a currency from a string in PHP, I\'ve had a look at number formatter but haven\'t got PHP 5.3 or the ability to add extensions.
The currency will on
I've got another answer. Might be a touch faster than using strpos, and would be better if there was any possibility of white space in the input.
$input = "£250.75";
$output = floatval(ltrim($input,"£"));
echo $output;
250.75
You could also add other currencies to the char list in ltrim:
$output = floatval(ltrim($input,"£$¢"));
This would strip $ or £ or ¢ from the left side of your number, as well as white space, which would break the solution above which uses strpos. Also, this would give the same result if the currency symbol was left off in some cases.