Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6366127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:22:58+00:00 2026-05-25T00:22:58+00:00

I am having trouble with a preg_match_all on a string that contains a degree

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:22:59+00:00Added an answer on May 25, 2026 at 12:22 am

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble with a string that comes from a webpage having foreign
Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
I'm having trouble with a regular expression in PHP that uses a potentially empty
I'm having trouble with preg_replace and I'm not sure that I use correct function.
having a bit of trouble with replacing things that are NOT 0-9A-Za-z[:space] because I
I am having trouble with string manipulation in php. I am writing a function
I'm having some trouble figuring this out. I have the following CSV string hello
Having trouble linking the Stomp.framework into an iPhone SDK application. http://code.google.com/p/stompframework/ I follow the
Having trouble getting one portion of my code to work. Building a rudimentary linked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.