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 6111275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:36:43+00:00 2026-05-23T14:36:43+00:00

Using the features currently available in PHP’s intl wrapper for ICU, how would you

  • 0

Using the features currently available in PHP’s intl wrapper for ICU, how would you go about checking for validity of a string’s encoding? (e.g. check for valid UTF-8)

I know it can be done with mbstring, iconv() and PCRE but I’m specifically interested in intl with this question.

  • 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-23T14:36:43+00:00Added an answer on May 23, 2026 at 2:36 pm

    I did some digging and found ICU unorm2_normalize() documentation. Its pErrorCode out parameter is interesting. The standard ICU error codes start around line 620 of utypes.h. So I tried this test script:

    $s = 'tête-à-tête';
    echo "normalizer_normalize(\$s) >> " 
         . var_export(normalizer_normalize($s), 1) . "\n";
    $s = "\xFF" . $s;
    echo "normalizer_normalize(\$s) >> " 
         . var_export($r=normalizer_normalize($s), 1) . "\n";
    if ($r===false)
        echo "normalizer_normalize() error: " 
             . intl_get_error_message() . "\n";
    // which outputs:
    normalizer_normalize($s) >> 'tête-à-tête'
    normalizer_normalize($s) >> false
    normalizer_normalize() error: Error converting input string to UTF-16: U_INVALID_CHAR_FOUND
    

    So I guess a test based on that and looking for the following three error codes would be a decent indication of bad UTF-8 encoding:

    U_INVALID_CHAR_FOUND Character conversion: Unmappable input sequence.
    U_TRUNCATED_CHAR_FOUND Character conversion: Incomplete input sequence.
    U_ILLEGAL_CHAR_FOUND Character conversion: Illegal input sequence/combination of input units.

    Or when I’m feeling lazy I could just use

    normalizer_normalize($s)===false
    

    Btw: I’m confused by this line of the ICU API spec:

    pErrorCode Standard ICU error code.
    Its input value must pass the
    U_SUCCESS() test, or else the function
    returns immediately. Check for
    U_FAILURE() on output or use with
    function chaining. (See User Guide for
    details.)

    The “the function returns immediately” phrase is encouraging re performance of my test but does “the function” refer to unorm2_normalize() or U_SUCCESS()? Any ideas?

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

Sidebar

Related Questions

I am currently using Telerik's carousel control, but it is lacking many features and
I want to start using .NET 3.5 features in an app that is currently
I am using some features that are provided in GCC v4+ and would like
I am currently using Pivotal Tracker and I like it for its features. The
We are currently using SQL Server 2005. We don't need the new features in
I am currently using glew to detect some GPU features of the bound openGL
Using the C# compilers query comprehension features, you can write code like: var names
I've been using a lot of new .NET 3.5 features in the work that
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Using Python, how does one parse/access files with Linux-specific features, like ~/.mozilla/firefox/*.default ? I've

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.