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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:29:17+00:00 2026-06-13T06:29:17+00:00

I am using a PHP 5.2.17 server + MySQL 5.1.65. I have a table

  • 0

I am using a PHP 5.2.17 server + MySQL 5.1.65.

I have a table containing a field that is VARCHAR utf8_general_ci and I fetch a record from this table.

This is how I open the connection, nothing special:

$link = mysql_connect('localhost', 'user', 'pass');

I need to respond with a JSON object that contain special characters Unicode escaped, I mean the \u00e1 notation.

 $result = mysql_query(sprintf("select * from data t where t.domain='%s'", escape($domain));


  while($row = mysql_fetch_array($result)) {
    $r[] = array(
      "tagid" => $row['DATAID'],
      "name" => $row['NAME']
    );
   )

$encoded = json_encode($r);
header('Content-type: application/json');
exit($encoded);

My problem is fields containing special characters (áé..) are returned as null in the JSON response.

After having Googled for a while I see that PHP 5.2 lack the json_encode parameters, so I need to unicode-escape name fields manually. But how could I do this?

  • 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-06-13T06:29:18+00:00Added an answer on June 13, 2026 at 6:29 am

    json_encode() should be able to handle UTF-8 data perfectly well – JSON is UTF-8 only, so it would be strange for PHP to not have this particular function as UTF-8 aware.

    $array = array('key' => 'せ');
    
    var_dump(json_encode($array)); // string(16) "{"key":"\u305b"}"
    

    Your column collation might be VARCHAR utf8_general_ci but that does not mean the characters are encoded as UTF-8. Your table should be created with:

    CREATE TABLE ... CHARACTER SET utf8
    

    And you should probably execute this as your first query:

    SET NAMES utf8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to connect to remote MySQL server with SSL from PHP using mysql_connect:
I have this mysql query using PHP and first part is working fine, but
I have created a survey system using php and mysql. I have a table
Original Question mysql-server-6.0.10 I have this problem, I'm using the COMPRESS function to update
I have a PHP application that stores PHP datetime to my MySQL table. I
I have a table that get its rows from a MYSQL database <table id=table1>
I am trying to connect to a MySQL server using PHP's 'mysql_connect()' function, but
I'm using PDO in my PHP application. It connects to a MySQL server on
i have made a server using php. The server is getting new information after
what is best way to send email from PHP using server authantication. Userid &

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.