preg_match() 添加无意义字符
我正在尝试匹配 DMS 纬度/经度。不过,我遇到了一些困难。到目前为止,我可以检测到该模式,但匹配不断在特殊字符旁边返回无意义的字符。这是我的代码:
//Begin code
$pattern = '/[0-9]{1,3}[:| |\x{00B0}]{0,1}[0-9]{1,2}[\']{0,1}[0-9]{1,2}["]{0,1}[N|S|E|W]/ui';
$value = "12°30'23\"S";
preg_match($pattern,$value,$matches);
print_r($matches);
//End code
这是输出:
Array ( [0] => 12°30'23"S )
如您所见,12 和 ° 之间存在不需要的 Â。
请帮忙!
I'm trying to match DMS latitude/longitude. I've run into a bit of a snag, though. I can detect the pattern so far, but the match keeps returning a nonsense character next to a special character. Here is my code:
//Begin code
$pattern = '/[0-9]{1,3}[:| |\x{00B0}]{0,1}[0-9]{1,2}[\']{0,1}[0-9]{1,2}["]{0,1}[N|S|E|W]/ui';
$value = "12°30'23\"S";
preg_match($pattern,$value,$matches);
print_r($matches);
//End code
and here is the output:
Array ( [0] => 12°30'23"S )
As you can see, an undesired  exists between the 12 and the °.
Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否已验证 HTTP 标头中的字符集设置为 UTF-8 或 Unicode?有关 PHP 和 Unicode 的更多信息,请参阅此页面:http://ibm. com/developerworks/library/os-php-unicode/index.html
Have you verified the charset is set to UTF-8 or Unicode in the HTTP headers? See this page for more info on PHP and Unicode: http://ibm.com/developerworks/library/os-php-unicode/index.html