duanju7199
2015-09-30 07:49
浏览 63
已采纳

用双引号回复反斜杠的php字符串

I have this string:

while($this->stmt->fetch()){
                $string=$string.'","'.$idRuolo;
                $i++;
            }       
            $str= ltrim($string,',"');

      $str=stripslashes($str); 

            echo json_encode($str);

I have tried everything but I can't delete the backslash from the result, this is the output:

"2\",\"1\",\"3"

this is what I want:

"2","1","3"

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongwo1234 2015-09-30 07:51
    已采纳

    Try str_replace.

    $str = str_replace("\\","",$str);
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • drvfqr5609 2015-09-30 07:56

    i think this code help for you

    <?php
    function removeslashes($string)
    {
        $string=implode("",explode("\\",$string));
        return stripslashes(trim($string));
    }
    
    
    $text="My dog don\\\\\\\\\\\\\\\\'t like the postman!";
    echo removeslashes($text);
    ?>
    
    评论
    解决 无用
    打赏 举报
  • dongyange1101 2015-09-30 07:58

    stripslashes($str);

    Returns a string with backslashes stripped off. (\' becomes ' and so on.) Double backslashes (\) are made into a single backslash (\ ).

    Your string contain double slash

    You use

    preg_replace('/\\\\/', '', $str);
    echo json_encode($str);
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题