ID: 45594
User updated by: neonira at gmail dot com
Reported By: neonira at gmail dot com
Status: Bogus
Bug Type: JSON related
Operating System: windows XP
PHP Version: 5.2.6
New Comment:
If I understand you well, a php source file, utf-8 encoded, with
embedded accentuated strings, brings the weird result that strings are
not UTF-8 encoded.
Is this what should really be understood from your answer? Is it
representative of the default PHP behavior, or is it just a local bug?
What correction may I do to my code to get the right result?
Previous Comments:
------------------------------------------------------------------------
[2008-07-22 22:05:35] [EMAIL PROTECTED]
Hint: You're not passing utf-8 here.. setlocale..
------------------------------------------------------------------------
[2008-07-22 22:04:52] [EMAIL PROTECTED]
RTFM: "This function only works with UTF-8 encoded data."
------------------------------------------------------------------------
[2008-07-22 15:32:45] neonira at gmail dot com
Description:
------------
I checked that the file encoding character set for the php source file
is UTF-8. So it means, I provide a real UTF-8 entry, and I don't need to
use ut8_encode.
It seems that accentuated caracters are truncated or not well managed
while json-encoding a string.
Reproduce code:
---------------
<?php
setlocale(LC_ALL, "fr");
class CT {
var $link;
var $str;
var $arr;
function document() {
$this->link = "http://www.neonira.com";
$this->str = "chaîne avec caractères accentués ... ";
$this->arr = array(1, 3, "lala", "123", array ( 'a', 'b', 'c'),
134);
}
}
$c = new CT();
$c->document();
echo json_encode($c);
?>
Expected result:
----------------
shell>php ../php/ct.php
{"link":"http:\/\/www.neonira.com","str":"chaîne avec caractères
accentués ... ","arr":[1,3,"lala","123",["a","b","c"],134]}shell>
Actual result:
--------------
shell>{107}php ../php/ct.php
{"link":"http:\/\/www.neonira.com","str":"cha","arr":[1,3,"lala","123",["a","b","c"],134]}shell>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45594&edit=1