Slash issue with json_encode. Why and how to solve it?

前端 未结 2 1073
长情又很酷
长情又很酷 2020-12-06 01:26

Why outputting this date (\"2011/7/11\") with json_encode displays (\"2011\\/7\\/11\")?

How can I convert \"2011\\/7\\/1

相关标签:
2条回答
  • 2020-12-06 01:54

    In PHP 5.4, you can use JSON_UNESCAPED_SLASHES:

    echo json_encode("2011/7/11", JSON_UNESCAPED_SLASHES);
    

    Otherwise, you have to do some trivial post-processing

    str_replace('\\/', '/', json_encode("2011/7/11"));
    

    Note that \/ is a valid way to represent / in JSON.

    0 讨论(0)
  • 2020-12-06 02:01
    $data_go = str_replace('\'','', $data_go);
    

    it will remove all forwards slashes and will give you desired result..

    0 讨论(0)
提交回复
热议问题