| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2009-08-21 19:31 UTC] paul dot wieland at port80ware dot com
 Description: ------------ json_encode is not removing the backslash from escaped forward slashes in my strings. It works fine on several machines running 5.2.x, but on one new machine running php 5.3.0 it returns the wrong result. Reproduce code: --------------- $my_string = 'Black/Gray'; var_dump($my_string); var_dump( json_decode( json_encode($my_string) ) ); Expected result: ---------------- string(10) "Black/Gray" string(10) "Black/Gray" Actual result: -------------- string(10) "Black/Gray" string(11) "Black\/Gray" PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 12:00:01 2025 UTC | 
No, it is definitely NOT fixed. php -v says: ================= PHP 5.3.1 (cli) (built: Feb 15 2010 17:30:23) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies ================= Test file: ================= <?= json_encode(array('test' => 'hello/world')) . chr(10); ================= Result: ================= {"test":"hello\/world"} =================dmitry, I don't understand your last comment. Of course / is escaped in the json encoded string. According to the spec it is supposed to be. The important part is that when you json_decode() it it comes back without the \ which it does: > php -v PHP 5.3.3-dev (cli) (built: Feb 10 2010 10:53:36) > php -a php > $enc = json_encode(array('test' => 'hello/world')); php > echo $enc; {"test":"hello\/world"} php > var_dump(json_decode($enc)); object(stdClass)#1 (1) { ["test"]=> string(11) "hello/world" }