【问题标题】:PHP - PDO return escaping slash, how to remove it?PHP - PDO 返回转义斜杠,如何删除它?
【发布时间】:2010-08-01 14:18:56
【问题描述】:

我正在使用 PDO 对象进行一些选择,但在 fetch 结果之后,我得到了将 ' 转义到 \' 的字符串,我该如何禁用它?

【问题讨论】:

  • magic_quotes 从 PHP 5.4 开始禁用。幸运的是,这不再是问题了。

标签: php pdo


【解决方案1】:

您似乎在使用Magic Quotes 时遇到了一些问题。您可以通过关注the instructions here 来禁用它们。强烈建议您禁用它们,而不是通过使用函数来去除斜线来回避它们。

【讨论】:

    【解决方案2】:

    您好像打开了magic quotes

    您实际上应该关闭 php.ini 中的魔术引号。

    或者在脚本中,你可以这样处理:

    if (get_magic_quotes_gpc())
    {
      $str = stripslashes($str);
    }
    

    现在可以正常使用$str变量了。

    【讨论】:

    • 最好在剥离斜线之前检查是否真正启用了magic_quotes,否则您将删除本应保持不变的斜线。
    • @tdammers:我在发表评论之前用这个更新了答案,无论如何谢谢:)
    【解决方案3】:

    我正在开发一个无法访问php.ini 的共享主机——ini_set() 也无法使用。这个 sn-p 就像一个魅力: [source]

    // since PHP 5
    if (get_magic_quotes_gpc()) {
        function stripslashes_gpc(&$value)
        {
            $value = stripslashes($value);
        }
       array_walk_recursive($_GET, 'stripslashes_gpc');
       array_walk_recursive($_POST, 'stripslashes_gpc');
       array_walk_recursive($_COOKIE, 'stripslashes_gpc');
       array_walk_recursive($_REQUEST, 'stripslashes_gpc');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-04
      • 2013-08-09
      • 2011-10-02
      • 1970-01-01
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      • 2012-07-23
      相关资源
      最近更新 更多