C2a0 And 20 String Comparision - Php - Stack Overflow

Just browsing Stack Overflow? Help us improve your experience. Sign up for research
    1. Home
    2. Questions
    3. Tags
    4. Users
    5. Companies
    6. Labs
    7. Jobs
    8. Discussions
    9. Collectives
    10. Communities for your favorite technologies. Explore all Collectives

  1. Teams

    Ask questions, find answers and collaborate at work with Stack Overflow for Teams.

    Try Teams for free Explore Teams
  2. Teams
  3. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Get early access and see previews of new features.

Learn more about Labs c2a0 and 20 string comparision Ask Question Asked 8 years, 10 months ago Modified 2 years, 6 months ago Viewed 3k times Part of PHP Collective 6

I have two utf-8 strings:

  • one saved as variable in php file (saved in UTF-8)
  • another gets externally from another with regular expression.

When I compare those two same space-separated strings, the result is false, meaning that they are not the same.

  • The string I saved as a variable is rendered as 20 with bin2hex (ascii encoded space symbol)
  • The string I got externally, processed with mb_strtolower($string, 'utf-8') is rendered as c2a0 with bin2hex (utf-8 space)

My questions is:

  1. Why when I save in utf-8 string not fully encoded as utf-8 (meaning space in ascii)?
  2. How to get rid of that problem?
Share Improve this question Follow edited Jan 21, 2016 at 14:43 zessx's user avatar zessx 68.7k28 gold badges137 silver badges164 bronze badges asked Jan 21, 2016 at 14:14 Velaro's user avatar VelaroVelaro 5011 gold badge4 silver badges21 bronze badges 1
  • 6 c2a0 is a no-break space whereas 20 is a space. – bobble bubble Commented Jan 21, 2016 at 14:18
Add a comment |

1 Answer 1

Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 4

As said in the comments c2a0 is a no-break space and 20 is normal space

Since you can see the problem in bin2hex you could:

$str = hex2bin(str_replace('c2a0', '20', bin2hex($str)));

or to put that another way:

$str = preg_replace('~\xc2\xa0~', ' ', $str); // typo corrected Share Improve this answer Follow edited May 8, 2022 at 21:25 user2373839's user avatar user2373839 13 bronze badges answered Sep 23, 2016 at 12:25 Ad Wicks's user avatar Ad WicksAd Wicks 3003 silver badges10 bronze badges Add a comment |

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid …

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Draft saved Draft discarded

Sign up or log in

Sign up using Google Sign up using Email and Password Submit

Post as a guest

Name Email

Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.

PHP Collective Join the discussion This question is in a collective: a subcommunity defined by tags with relevant content and experts.
  • The Overflow Blog
  • Your docs are your infrastructure
  • Featured on Meta
  • More network sites to see advertising test [updated with phase 2]
  • We’re (finally!) going to the cloud!
  • Call for testers for an early access release of a Stack Overflow extension...
Visit chat

Linked

1 Mongodb search with space between word 2653 How do I check if a string contains a specific word? 2322 How do you parse and process HTML/XML in PHP? 1345 What's the difference between utf8_general_ci and utf8_unicode_ci? 1703 startsWith() and endsWith() functions in PHP 1195 Check whether a string matches a regex in JS 1154 What's the difference between UTF-8 and UTF-8 with BOM? 165 How can I match multiple occurrences with a regex in JavaScript similar to PHP's preg_match_all()? 866 How to count string occurrence in string? 78 Force encode from US-ASCII to UTF-8 (iconv)

Hot Network Questions

  • Publishing corollaries of previously published results
  • Inheritance Tax: the Estate or the Beneficiaries?
  • How Do Copulas Provide Insight Into Dependence Between Random Variables?
  • Study("somewhere")
  • Will a laptop battery that stays connected to its charger be damaged?
  • What is another word for when someone’s statement lacks integrity or meaning?
  • Student is almost always late, and expects me to re-explain everything he missed
  • What's a good way to append a nonce to ciphertext in Python for AES GCM in Python?
  • Identifying a TNG episode where Dr. Pulaski instructs another doctor on a sling
  • Is BNF grammar in TeXbook correct?
  • Configure Linux to regularly sync cached data to disk
  • Counting birds outside my house
  • How do I add a trusted check constraint quickly
  • If scent means a pleasant smell, why do we say "lovely scent" or "sweet scent"?
  • What does GB Shaw mean when he says "like the butcher's wife in the old catch" here?
  • Is there any penalty for providing half cover to another creature?
  • Different projection matrices, don't understand how to proceed
  • Why is it safe to soak an electric motor in isopropyl alcohol but not distilled water?
  • What powers do police have to force people onto trains?
  • Why don't routers answer ARP requests for IP addresses they can handle even if they aren't assigned that IP address themselves?
  • Syllables of noun ‹cavalier›?
  • Late 70s/Early 80s android made-for-TV movie
  • Does synonymy seep down to the fragments of theories?
  • How do different observers decide if they are looking at the same thing?
more hot questions Question feed Subscribe to RSS Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-php

Từ khóa » C2 A0 Vs 20