I have a string in this format.
我有一个这种格式的字符串。
"1784_Anarchy+Brew+Co~Unit+5+Whitehouse+Farm+Centre~Stannington~Morpeth~NE61+6AW_^55.13033~-1.702607"
Would the pattern look something like
这个模式会是什么样的
preg_match_all("\^d+\", $map, $out, PREG_PATTERN_ORDER);
so the lat -- \^d+.d+ ? the lng -- \~d+.d+ ?
所以lat - \ ^ d + .d +? lng - \ ~d + .d +?
trying to get the lat and long values -- lat: 55.13033 lng: -1.702607
试图得到纬度和长值 - 纬度:55.13033 lng:-1.702607
2 个解决方案
#1
2
If lat and lng string position remain constant, here is a quick way around it. else post other instances
如果lat和lng字符串位置保持不变,这里有一个快速的方法。否则发布其他实例
$str = '1784_Anarchy+Brew+Co~Unit+5+Whitehouse+Farm+Centre~Stannington~Morpeth~NE61+6AW_^55.13033~-1.702607';
preg_match_all("/(?<=[\^|\~])\-?([\d\.]+)/", $str, $matches);
$lat = $matches[0][0];
$lng = $matches[0][1];
echo "lat: $lat, Lng: $lng";
//output: lat: 55.13033, Lng: -1.702607
#2
0
the following regex expression should isolate coordinates:
以下正则表达式应该隔离坐标:
(-?\d{1,3}\.)\d{5,6}
The block inside () will match an optional '-' for negative LAT/LONG followed by group of 1 to 3 digits ( as longitude can be up to 180) followed by a 'dot'.
内部()块将匹配一个可选的' - '表示负LAT / LONG,后跟一组1到3位数(经度可以高达180),然后是'点'。
The rest of the expression will match from 5 to 6 digits ( as per the precision that seem to be in your example ).
表达式的其余部分将匹配5到6位数(根据示例中的精度)。
As long as the search string keep more or less like the one stated, this should work:
只要搜索字符串保持或多或少与所陈述的一致,这应该工作:
Hope this helps !!
希望这可以帮助 !!
#1
2
If lat and lng string position remain constant, here is a quick way around it. else post other instances
如果lat和lng字符串位置保持不变,这里有一个快速的方法。否则发布其他实例
$str = '1784_Anarchy+Brew+Co~Unit+5+Whitehouse+Farm+Centre~Stannington~Morpeth~NE61+6AW_^55.13033~-1.702607';
preg_match_all("/(?<=[\^|\~])\-?([\d\.]+)/", $str, $matches);
$lat = $matches[0][0];
$lng = $matches[0][1];
echo "lat: $lat, Lng: $lng";
//output: lat: 55.13033, Lng: -1.702607
#2
0
the following regex expression should isolate coordinates:
以下正则表达式应该隔离坐标:
(-?\d{1,3}\.)\d{5,6}
The block inside () will match an optional '-' for negative LAT/LONG followed by group of 1 to 3 digits ( as longitude can be up to 180) followed by a 'dot'.
内部()块将匹配一个可选的' - '表示负LAT / LONG,后跟一组1到3位数(经度可以高达180),然后是'点'。
The rest of the expression will match from 5 to 6 digits ( as per the precision that seem to be in your example ).
表达式的其余部分将匹配5到6位数(根据示例中的精度)。
As long as the search string keep more or less like the one stated, this should work:
只要搜索字符串保持或多或少与所陈述的一致,这应该工作:
Hope this helps !!
希望这可以帮助 !!