Home > Backend Development > PHP Tutorial > 求帮:php怎么用正则获取浮点数?

求帮:php怎么用正则获取浮点数?

WBOY
Release: 2016-06-23 13:58:02
Original
971 people have browsed it

'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));
Copy after login


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

$s = 'tmap 116.123456,39.123456';preg_match_all('/[\d.]+/', $s, $r);print_r($r[0]);
Copy after login
Array(    [0] => 116.123456    [1] => 39.123456)
Copy after login

$s='tmap 116.123456,39.123456';$ar = preg_split('/[\s,]+/',$s);print_r($ar);
Copy after login

$str = 'tmap 116.123456,39.123456';print_r(preg_split('/[\s,]/', $str));
Copy after login

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template