0

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!

rogue780
  • 155
  • 1
  • 1
  • 9
  • 2
    Have you verified the charset is set to utf-8 or unicode in the http headers? see this for more info on php and unicode: http://www.ibm.com/developerworks/library/os-php-unicode/index.html – Peter Smith Feb 06 '12 at 04:13
  • Well, I feel foolish. Thanks Peter – rogue780 Feb 06 '12 at 04:20
  • @PeterSmith, how about posting that as an answer? That would help get the question off the unanswered questions list... – Highly Irregular Feb 08 '12 at 02:07

1 Answers1

1

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

salathe
  • 51,324
  • 12
  • 104
  • 132
Peter Smith
  • 849
  • 2
  • 11
  • 28