求帮:php如何用正则获取浮点数
程序员文章站
2023-12-26 21:18:51
...
求帮:php怎么用正则获取浮点数?
'tmap 116.123456,39.123456‘
tmap后面有空格,
我想获取116.123456
和39.123456两个浮点坐标,请问怎么用正则获取?
------解决方案--------------------
Array
(
[0] => 116.123456
[1] => 39.123456
)
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
'tmap 116.123456,39.123456‘
tmap后面有空格,
我想获取116.123456
和39.123456两个浮点坐标,请问怎么用正则获取?
------解决方案--------------------
$str = 'tmap 116.123456,39.123456';
preg_match_all('/[^\s]+/', $str, $match);
$numstr = $match[0][1];
print_r(explode(',',$numstr));
Array
(
[0] => 116.123456
[1] => 39.123456
)
------解决方案--------------------
$s = 'tmap 116.123456,39.123456';
preg_match_all('/[\d.]+/', $s, $r);
print_r($r[0]);
Array
(
[0] => 116.123456
[1] => 39.123456
)
------解决方案--------------------
$s='tmap 116.123456,39.123456';
$ar = preg_split('/[\s,]+/',$s);
print_r($ar);
------解决方案--------------------
$str = 'tmap 116.123456,39.123456';
print_r(preg_split('/[\s,]/', $str));
相关文章
相关视频