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

  • Home
  • SEARCH
  • 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 6033825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:32:24+00:00 2026-05-23T05:32:24+00:00

I am new to PHP & JSON and based on a tutorial I made

  • 0

I am new to PHP & JSON and based on a tutorial I made a simple web service which returns the contents of a table of a mysql db.

The output is in both XML and JSON and the database caracter set is UTF-8. my problem is that some fields contain Greek characters and do not appear correctly in the JSON output format (in XML everything is fine). Any idea what might be wrong?

The PHP file is the following:

<?php

/* require the place_name_en as the parameter */

      /* soak in the passed variable or set our own */
      $number_of_places = isset($_GET['num']) ? intval($_GET['num']) : 1; //10 is the default
      $format = strtolower($_GET['format']) == 'json' ? 'json' : 'xml'; //xml is the default


       /* connect to the db */
      $link = mysql_connect('xxx','xxx','xxx') or die('Cannot connect to the DB');

     mysql_select_db('foodbar',$link) or die('Cannot select the DB');
     mysql_set_charset('utf8',$link);
     mysql_query('set names utf8'); 

      /* grab the posts from the db */
      $query = 'SELECT * FROM test';
      $result = mysql_query($query,$link) or die('Errant query:  '.$query);


      /* create one master array of the records */
      $posts = array();

      if(mysql_num_rows($result)) {
        while($place = mysql_fetch_assoc($result)) {
          $places[] = array('place'=>$place);

      }

      }

      if($format == 'json') {
      /* output in json format */
            header('Content-type: application/json');
            echo json_encode(array('places'=>$places));
    }
      else {

      /* output in xml format */

        header('Content-type: text/xml; charset=utf-8');
         echo '<?xml version="1.0" encoding="utf-8"?>';
        echo '<places>';
        foreach($places as $index => $place) {
          if(is_array($place)) {
            foreach($place as $key => $value) {
              echo '<',$key,'>';
              if(is_array($value)) {
                foreach($value as $tag => $val) {
                  /*echo '<',$tag,'>',htmlentities($val,ENT_QUOTES,"utf-8"),'</',$tag,'>';*/
                        echo '<',$tag,'>',$val,'</',$tag,'>';
                }
              }
              echo '</',$key,'>';
            }
          }
        }
        echo '</places>';
        }

      @mysql_close($link);

?>

You can test the xml output here.

But when json format is returned there is a problem with Greek characters. they appear like:

\u03b4\u03b4\u03b5\u03c3\u03c3\u03b4\u03b4\u03c6

Any idea? Thank you in advance!

P.S. DB settings: MySQL charset: UTF-8 Unicode (utf8) and MySQL connection collation: utf_8_unicode_ci

  • 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-23T05:32:25+00:00Added an answer on May 23, 2026 at 5:32 am

    json_encode() encodes unicode characters to \uxxxx sequences. It’s normal. JS will understand them

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

Sidebar

Related Questions

<?php session_start(); require_once('JSON.php'); $url= 'http://ajax.googleapis.com/ajax/services/search/web?rsz=large&v=1.0&q='. $_POST['searchquery'].'&key=ABQIAAAA4oH5MwaexHdhZg4UWRNB1RT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTzUf4N43torAasiY6JD5CaJS6n7Q&userip=http://localhost/'; echo $url; // use fopen and fread to
I am pretty new to php, but I am learning! I have a simple
I'm a spanking new developer to the PHP & SQL scene. I've only done
I'm quite new to Zend & JSON, however I have the need to learn.
I have to return data fetched from MySQL table into a php file as
Has anyone ever modified the post-new.php file in their WordPress installation? I want to
To put it simply i am a fairly new PHP coder and i was
We are in the startup build phase of a new PHP webapp that will
Rather new to php, so sorry if this seems stupid. I'm really copying a
Im new to PHP and I can't figure out what the rules are for

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.