preg_match coordinates with degree sign

情到浓时终转凉″ 提交于 2019-12-06 16:09:01

Perhaps you should try ignoring the actual degrees and tick marks and focus just on the data you want to grab.

(\d+)\D+(\d+)\D+(\d+)\.(\d+)\W(\w+)\W+(\d+)\D+(\d+)\D+(\d+)\.(\d+)\W(\w)

This regex should capture the following data:

41
12
27
84
N
16
18
40
15
E

(Edit2: Corrected to properly pick up the N without punctuation.)

You're missing the /u modifier to make the engine interpret the pattern as Unicode.

What is stopping you from using the ° character literally?

/
  (\d+\s*°\s*  \d+\s*'\s*  \d+\s*\.\s*\d+\s*"\s*  [NS])
  \s*,\s*
  (\d+\s*°\s*  \d+\s*'\s*  \d+\s*\.\s*\d+\s*"\s*  [EW])
/xi

Use mb_ereg_match instead to support UTF-8 chars. Docs: http://php.net/manual/en/book.mbstring.php

Initialize mb* like this:

mb_regex_encoding('UTF-8');
mb_internal_encoding('UTF-8');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!