如何确定一个PHP字符串是否只包含经度和纬度 [英] How to determine if a PHP string ONLY contains latitude and longitude
问题描述
$ query =-33.805789 我必须使用可能包含Lat / Long数据的字符串。 ,151.002060\" ;
$ query =-33.805789,151.002060;
$ query =OVER HERE:-33.805789,151.002060;
就我的目的而言,前2个字符串是正确的,但最后一个不是。我试图找出一个匹配模式,匹配经纬度,长逗号,逗号和空格。但是如果字符串中包含数字,空格,点号,减号和逗号之外的任何内容,那么它应该会失败。
希望这是有道理的,而TIA !
^ [+ - ]?\ d + \.\d + ,?[+ - ]?\ d + \.\d + $
I have to work with strings which may contain Lat/Long data, like this: For my purposes, the first 2 strings are correct, but the last one isn't. I am trying to figure out a match pattern which would match a lat and long separated by a comma, or a comma and a space. But if it has anything in the string other than numbers, spaces, dots, minus signs and commas, then it should fail the match. Hope this makes sense, and TIA! The 这篇关于如何确定一个PHP字符串是否只包含经度和纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! ^
在开头,$query = "-33.805789,151.002060";
$query = "-33.805789, 151.002060";
$query = "OVER HERE: -33.805789,151.002060";
^[+-]?\d+\.\d+, ?[+-]?\d+\.\d+$
^
at the start and $
at the end make sure that it matches the complete string, and not just a part of it.