Reputation: 25516
So I am parsing a google spreadsheet and stuck at this problem:
$str = '20.00 €';
preg_match("/\d*.\d*/", $str, $output);
var_dump($output);
working example: http://www.phpliveregex.com/p/ggg
This is how it looks like: http://sandbox.onlinephpfunctions.com/code/14f9f8aa635f329f5b150b626d84da46746f064c
There is some white space which won't allow preg_match
to find 20.00
. Don't know how to deal with it. I have tried trim
but it won't work..
Upvotes: 1
Views: 365
Reputation: 76
Just need to escape the dot character.
$str = '20.00 €';
preg_match("/\d*\.\d*/", $str, $output);
var_dump($output);
Upvotes: 2
Reputation: 5039
You can remove spaces in between the string using:
$string = preg_replace('/\s+/', '', $string);
Upvotes: 2