Re: pear ajax and accented letters

From: Date: Wed, 18 Jan 2006 00:22:18 +0000
Subject: Re: pear ajax and accented letters
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-22569@lists.php.net to get a copy of this message
Well it looks like your running into the php such at utf8 problems. You might try changing your setup so the mbstring functions override there generic versions. caractères' as 'caractères' is broken utf8, the JSON unserializer should be handling that fine on the PHP side, and i'm able to round trip those strings through it, but things get problematic if you run any string processing methods on it. -josh Adi wrote:
all works great....onel ast question...when data is sent from the client, do I have to decode/unserialize it? when I send the word 'caractères' it is interpreted as 'caractères' on the server side. looks like something internal to ajax is changing the accented character...how do I change it back to its original state? thanks... adam... On 1/17/06, *Joshua Eichorn* <josh@bluga.net <mailto:josh@bluga.net>> wrote:
    Ok took me awhile to find the problem, but i got if figured out now.
    The JSON code can only ascii and UTF-8 encoded strings, i'm not sure
    what your sending it but its not one of those.  I'm guessing its UTF-8
    thats been broken in some way.
    You'll want to reload your JSON.php and then recode all your strings
    before sending them to JSON.
    In my testing i could send your string from javascript to php and
    back.
    And from PHP to js but i had to recode first like so:
    $returnData = array('word' => mb_convert_encoding('Français','UTF-8'),
    'suggestion' => array(mb_convert_encoding('Français','UTF-8'),
    mb_convert_encoding('caractères','UTF-8')));
            return $returnData;
    -josh
    Adi wrote:
also getting the following notice: PHP Notice: Uninitialized string offset: 7 in /data/www2/newFramework/lib/pear/HTML/AJAX/JSON.php on line 321 On 1/17/06, Joshua Eichorn <josh@bluga.net
    <mailto:josh@bluga.net>> wrote:
It looks to me like its not escaping some of the unicode characters properly. The unicode escape sequence is \u followed by 4 characters so
    im not
sure what the second set of 4 does. For a test i added in the second \u and things seem to be ok: http://bluga.net/projects/HTML_AJAX/test.php There must be some bug in unicode escaping, I put in an
    untested fix
that should fix the problem as long as you have mbstring
    installed.
Just grab http://svn.bluga.net/HTML_AJAX/trunk/AJAX/JSON.php again. -josh Adi wrote:
The code runs now, however, json is still having trouble
    unserializing
my
data. I am sending back a multidimentional array that has the
    following
structure: arra('word' => 'aple',
       'suggestions' => array('Apple', 'apple', 'pale',
    'ample', 'ale',
'ape', 'maple')); This is what the server is returning...: raw:
    [{"word":"caract\u00e8res","suggestions":["caract\u00720065s","caract\u00720065"]}]
unserialized: the two word suggestions print like this: - caractr0065s - caractr0065 Please advise... Thanks... On 1/17/06, Joshua Eichorn <josh@bluga.net
    <mailto:josh@bluga.net>> wrote:
Adi wrote:
I reconfigured my php with multibyte support and I can post
    data to
the
server with no problem, however, now the php JSON server
    side code is
producing further problems...its just a notice, but the data
    returned
is
useless: PHP Notice: Uninitialized string offset: 7 in /data/www2/newFramework/lib/pear/HTML/AJAX/JSON.php on line 120 Is there a way around this by any chance? Thanks for your time...
The JSON code is actually from Services_JSON which hasn't had a
released
yet, there is an updated version that might fix this
    problem.  I'll
update the version in HTML_AJAX before the next release but
    that could
be a week or so. If you want to give the updated JSON code a try you can
    downloaded an
updated version from: http://svn.bluga.net/HTML_AJAX/trunk/AJAX/JSON.php
Just replace
    /data/www2/newFramework/lib/pear/HTML/AJAX/JSON.php with
the updated file. If that doesn't fix it let me know and
    will get
Michal involved. -josh -- Take care... Adam -- Take care... Adam -- Take care... Adam


« previous php.pear.general (#22569) next »