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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:00:31+00:00 2026-05-19T02:00:31+00:00

I’m having a problem with some characters like ‘í’ or ‘ñ’ working in a

  • 0

I’m having a problem with some characters like ‘í’ or ‘ñ’ working in a web project with PHP and MySQL.

The database table is in UTF-8 charset and the web page is ISO-8859-1 (latin-1). at first look everything is handled ok, but a problem is coming when I use the JSON_ENCODE function of PHP.

When I get a query result, let’s say, this row:

 | ID | VALUE |
 --------------------
 | 1 | Línea |

I got the following (correct) array in PHP:

 Array("ID"=>"1","VALUE"=>"Línea");

So far, so good. But, when i apply the JSON_ENCODE

 $result = json_encode($result);
 //$result is {"id":"1","value":"L"}

Then i tried some coding/decoding but i couldn’t get the right result.

First I tried to decode the UTF-8 chars like follow:

 $result['value'] = utf8_decode($result['value']);
 //and I get $result['value'] is "L?a"

Then I tried with mb functions:

 $result['value'] = mb_convert_encoding($result['value'],"ISO-8859-1","UTF-8");
 //and I get that $result['value'] is "Lnea"

I don’t really know why is the Json_encode breaking my string and i can’t figure out what else to try. I will appreciate any help 🙂

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-19T02:00:31+00:00Added an answer on May 19, 2026 at 2:00 am

    The documentation for json_encode states that the function will only work on UTF-8 data. If it’s not working for you, it means that your data is not UTF-8.

    To understand what’s going wrong, you need to know what your connection character set is. Is it UTF-8? Something else? Use SET NAMES utf-8 and see if it makes any difference.

    Assuming the connection character set is indeed UTF-8, json_encode should work just fine. Then, you still have the final issue of converting the encoded data to ISO-8859-1. For example:

    // assume any strings in $result are UTF-8 encoded
    $json = json_encode($result);
    
    $output = mb_convert_encoding($json, 'ISO-8859-1', 'UTF-8');
    
    echo $output;
    

    If it still doesn’t work, it means that your UTF-8 strings contain characters not available in the ISO-8859-1 character set. There’s nothing you can do about that.

    Update:

    When debugging complex character set conversions like this, you can use file_put_contents to write intermediate results to a file which you can inspect with a hex editor. This will help confirm that the output of a particular step of the process is correct or not.

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

Sidebar

Related Questions

No related questions found

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.