Parsing Javascript (not JSON) in PHP

后端 未结 5 1592
[愿得一人]
[愿得一人] 2020-12-01 11:06

I have a php string containing the serialization of a javascript object :

$string = \'{fu:\"bar\",baz:[\"bat\"]}\';

The actual string is fa

5条回答
  •  旧巷少年郎
    2020-12-01 11:37

    thank luttkens

    the CJON::decode() class of the Yii-framework works perfectly !

    require_once ($_SERVER['DOCUMENT_ROOT']."/phplib/CJSON.php");
    
    $json = new CJSON();
    $data = $json->decode('{ url : "/jslib/maps/marker/marker_red.png", height : 34, width : 20, anchorIcon : [5,25.5], anchorText : [0,2], }', true);
    
    print_r( $data );
    

    result :

    Array
    (
        [url] => /jslib/maps/marker/marker_red.png
        [height] => 34
        [width] => 20
        [anchorIcon] => Array
            (
                [0] => 5
                [1] => 25.5
            )
    
        [anchorText] => Array
            (
                [0] => 0
                [1] => 2
            )
    
    )
    

提交回复
热议问题