dongyuan9109 2011-02-03 23:30
浏览 675
已采纳

试图从我的json中找到并摆脱这个\ u0000

This is my $var from json_encode:

{
"key1":"\u0000data1",
"key2":"\u0000data2",
"key3":"\u0000data3",
"key4":"\u0000data4
}

I would like to do this:

echo json_encode(str_replace ("\\u0000", "",  $var));

in order to get rid of the preceding \u0000 that's showing up, the line above doesn't work to strip it.

  • 写回答

2条回答 默认 最新

  • duan111112 2011-02-03 23:33
    关注

    You'll have to apply the function the other way round:

    echo str_replace('\\u0000', '', json_encode($var));
    

    This is because $var is an array. You'd have to iterate over all its entries and look for the \0 byte otherwise.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?