Remove all backslashes from PHP urldecoded string

后端 未结 5 1102
悲哀的现实
悲哀的现实 2021-01-18 05:03

I am trying to remove all backslashes from a url-decoded string, but it is outputting \\ rather than outputting the url-decoded string with \\ removed.

Please can yo

相关标签:
5条回答
  • 2021-01-18 05:23

    You want to use stripslashes(), because that's exactly what it is for. Also looks shorter:

    echo urldecode(stripslashes($json));
    

    You should however consider disabling magic_quotes rather.

    0 讨论(0)
  • 2021-01-18 05:24

    This is working for 100% correctly.

    $attribution = str_ireplace('\r\n', '', urldecode($attribution));
    
    0 讨论(0)
  • 2021-01-18 05:28

    Try this instead, your arguments for str_replace are incorrect.

    <?php
    $json = $_GET['ingredients'];
    echo urldecode(str_replace("\\","",$json));
    ?>
    
    0 讨论(0)
  • 2021-01-18 05:32

    Accoring to php.net's str_replace docs, the first argument is what you are searching for, the second is what you are replacing with, and the third is the string you are searching in. So, you are looking for this:

    str_replace("\\","", $json)
    
    0 讨论(0)
  • 2021-01-18 05:41

    You're wrongly using str_replace

    str_replace("\\","", $json)
    
    0 讨论(0)
提交回复
热议问题