skyline
1
If i have a number in a string like this:
a word: "2 291.59159 another word"
how can i get it? I was doing an explode on a space until i discovered some of the numbers, when in the 1,000’s had a space in them!
I have this for number match:
$string = ereg_replace("[^0-9]", "",$ms);
but could i add decimals and spaces to the match, and then maybe trim the extra space off the end??
Why do you think the 2 and 291 are the same word? No country in the world uses a space as a separator.
Also, is there always exactly one number per string, or can there be multiple?
skyline
3
well this does! i’m exploding a larger string so this is only number
Then:
$number = preg_replace('/[^0-9\\.]/', '', $ms);
$number = trim($number, '.');