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

The Archive Base Latest Questions

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

So I have an array of strings, and all of the strings are using

  • 0

So I have an array of strings, and all of the strings are using the system default ANSI encoding and were pulled from a SQL database. So there are 256 different possible character byte values (single byte encoding).
Is there a way I can get json_encode() to work and display these characters instead of having to use utf8_encode() on all of my strings and ending up with stuff like \u0082?

Or is that the standard for JSON?

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

    Is there a way I can get json_encode() to work and display these characters instead of having to use utf8_encode() on all of my strings and ending up with stuff like “\u0082”?

    If you have an ANSI encoded string, using utf8_encode() is the wrong function to deal with this. You need to properly convert it from ANSI to UTF-8 first. That will certainly reduce the number of Unicode escape sequences like \u0082 from the json output, but technically these sequences are valid for json, you must not fear them.

    Converting ANSI to UTF-8 with PHP

    json_encode works with UTF-8 encoded strings only. If you need to create valid json successfully from an ANSI encoded string, you need to re-encode/convert it to UTF-8 first. Then json_encode will just work as documented.

    To convert an encoding from ANSI (more correctly I assume you have a Windows-1252 encoded string, which is popular but wrongly referred to as ANSI) to UTF-8 you can make use of the mb_convert_encoding() function:

    $str = mb_convert_encoding($str, "UTF-8", "Windows-1252");
    

    Another function in PHP that can convert the encoding / charset of a string is called iconv based on libiconv. You can use it as well:

    $str = iconv("CP1252", "UTF-8", $str);
    

    Note on utf8_encode()

    utf8_encode() does only work for Latin-1, not for ANSI. So you will destroy part of your characters inside that string when you run it through that function.


    Related: What is ANSI format?


    For a more fine-grained control of what json_encode() returns, see the list of predifined constants (PHP version dependent, incl. PHP 5.4, some constants remain undocumented and are available in the source code only so far).

    Changing the encoding of an array/iteratively (PDO comment)

    As you wrote in a comment that you have problems to apply the function onto an array, here is some code example. It’s always needed to first change the encoding before using json_encode. That’s just a standard array operation, for the simpler case of pdo::fetch() a foreach iteration:

    while($row = $q->fetch(PDO::FETCH_ASSOC))
    {
      foreach($row as &$value)
      {
        $value = mb_convert_encoding($value, "UTF-8", "Windows-1252");
      }
      unset($value); # safety: remove reference
      $items[] = array_map('utf8_encode', $row );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of strings: @array I want to concatenate all strings beginning
Specifically, I have an array of strings called val, and want to replace all
I have an array of strings. How can I convert it to System.Collections.ArrayList?
I have a class that creates a static array of all properties, using a
I have a string. I need to replace all instances of a given array
I have an array of strings in python which each string in the array
I have an array of strings var controlsToGet = new[] {lblHome,lblContact}; I have List<LanguageControl>
I have an array of strings that I want to use for button titles
I have an array of strings plus one additional string. I want to use
Say I have an array of strings in a php array called $foo with

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.