Home >Backend Development >PHP Tutorial >求帮:php如何用正则获取浮点数

求帮:php如何用正则获取浮点数

WBOY
WBOYOriginal
2016-06-13 11:55:551645browse

求帮:php怎么用正则获取浮点数?
'tmap 116.123456,39.123456‘
tmap后面有空格,
我想获取116.123456
和39.123456两个浮点坐标,请问怎么用正则获取?
------解决方案--------------------

<br />$str = 'tmap 116.123456,39.123456';<br />preg_match_all('/[^\s]+/', $str, $match);<br />$numstr = $match[0][1];<br />print_r(explode(',',$numstr));<br />


Array
(
    [0] => 116.123456
    [1] => 39.123456
)

------解决方案--------------------
$s = 'tmap 116.123456,39.123456';<br />preg_match_all('/[\d.]+/', $s, $r);<br />print_r($r[0]);
Array<br />(<br />    [0] => 116.123456<br />    [1] => 39.123456<br />)<br /><br />

------解决方案--------------------
$s='tmap 116.123456,39.123456';<br />$ar = preg_split('/[\s,]+/',$s);<br />print_r($ar);

------解决方案--------------------
$str = 'tmap 116.123456,39.123456';<br />print_r(preg_split('/[\s,]/', $str));

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn