How to remove backslash on json_encode() function?

前端 未结 10 1798
逝去的感伤
逝去的感伤 2020-12-03 04:42

How to remove the (\\)backslash on a string? when using echo json_encode() ?

For example:



        
相关标签:
10条回答
  • 2020-12-03 05:21

    If you using PHP 5.2, json_encode just expect only 1 parameter when call it. This is an alternative to unescape slash of json values:

    stripslashes(json_encode($array))
    

    Don't use it if your data is complicated.

    0 讨论(0)
  • 2020-12-03 05:22
    json_encode($response, JSON_UNESCAPED_SLASHES);
    
    0 讨论(0)
  • 2020-12-03 05:25

    Yes it's possible. Look!

    $str = str_replace('\\', '', $str);
    

    But why would you want to?

    0 讨论(0)
  • 2020-12-03 05:28

    Simpler way would be

    $mystring = json_encode($my_json,JSON_UNESCAPED_SLASHES);
    
    0 讨论(0)
提交回复
热议问题