0

I try to split a GPS coordinate with function:

$long = "13°47'52.544\"E";
$res = preg_split("/[°'\"]/", $long);

but result is:

array(0=>13, 1=>, 2=>47, 3=>52.544, 4=>E)

why item 1 is add to result ?

Example here: http://www.phpliveregex.com/p/nPv

Syscall
  • 19,327
  • 10
  • 37
  • 52
Skyfox
  • 35
  • 1
  • 7

1 Answers1

1

° is two bytes 0xC2 0xB0 and you are not in Unicode "mode". Therefore, it is splitting on the 0xC2 and again on the 0xB0, with an empty item in the middle.

Enable Unicode mode with the u modifier.

$long = "13°47'52.544\"E";
$res = preg_split("/[°'\"]/u", $long);
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592