使用preg_match_all和度数符号时遇到问题

I am having trouble with a preg_match_all on a string that contains a degree symbol. The sample of code is below.

//Sample data
$x = "<array_0>
        <id>text-21650</id>
        <text>Lat/Long 38° 57' 34 N,  106° 21' 38 W</text>
      </array_0>";

$reels = '/<(\w+)\s*([^\/>]*)\s*(?:\/>|>(.*)<\/\s*\\1\s*>)/s';

preg_match_all($reels, $x, $elements);

foreach ($elements[1] as $ie => $xx) {
  $name = $elements[1][$ie];
  $cdend = strpos($elements[3][$ie], "<");
  if ($cdend > 0) {
    $xmlary[$name] = substr($elements[3][$ie], 0, $cdend - 1);
  }

  if (preg_match($reels, $elements[3][$ie]))
    $xmlary[$name] = processEl($elements[3][$ie]);
  else if ($elements[3][$ie] !== null) {
    $xmlary[$name] = $elements[3][$ie];
  }
}

For some reason it doesn't work properly with the degree symbols in there. If I take it out it works. I would really like to find a way that they can stay in there without changing them. I am also wondering if there may be other extended character that could cause a problem too.

Any help would be greatly appreciated. Thanks

Have a look at this previous answer on StackOverflow.

Basically you will have to switch to Unicode matching.

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');

I had the same problem, and this other post from stackoverflow helped me. Basically, to look for a degree symbol, you'd use \x{00B0}, ie.

preg_match_all("/\x{00B0}/", $x, $elements);