dongzhao8233 2013-05-29 05:52
浏览 182
已采纳

斜杠添加到JSON

In live server unwanted slashes appending to encoding JSON, wherever single quote present.

Actually i'm trying to do rename Number as Nu'mber, just adding a single in between.

PHP Version 5.3.21

Result: {"values":"Nu\\'mber","lastvalue":"Number"}

i.e. ' replaced with \\'

whereas in my local-server, its working perfectly

PHP Version 5.3.13

Result: {"values":"Nu'mber","lastvalue":"Number"}

Also, i used stripslashes(), but no use of it. in some cases, i have to reuse the result JSON if i do that, more slashes appended .is this PHP version problem?

  • 写回答

1条回答 默认 最新

  • douyi8408 2013-05-29 05:55
    关注

    This has to do with magic quotes. You can turn them off in php.ini or in the code.

    From te manual, in php.ini:

    ; Magic quotes for incoming GET/POST/Cookie data.
    magic_quotes_gpc = Off
    
    ; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
    magic_quotes_runtime = Off
    
    ; Use Sybase-style magic quotes (escape ' with '' instead of \').
    magic_quotes_sybase = Off
    

    Or in your php code:

    if (get_magic_quotes_gpc()) {
        $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
        while (list($key, $val) = each($process)) {
            foreach ($val as $k => $v) {
                unset($process[$key][$k]);
                if (is_array($v)) {
                    $process[$key][stripslashes($k)] = $v;
                    $process[] = &$process[$key][stripslashes($k)];
                } else {
                    $process[$key][stripslashes($k)] = stripslashes($v);
                }
            }
        }
        unset($process);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 JETSON NANO
  • ¥15 VS开发qt时如何在paintgl函数中用pushbutton控制切换纹理
  • ¥20 关于 openpyxl 处理excel文件地问题
  • ¥15 MS中不知道高分子的构型怎么构建模型
  • ¥60 QQOP数据,什么是op数据号,怎么提取op数据!能不能大量提取(语言-c语言)
  • ¥15 matlab代码 关于微分方程和嵌套的分段函数。
  • ¥15 onlyoffice编辑完后立即下载,下载的不是最新编辑的文档
  • ¥15 求caverdock使用教程
  • ¥15 Coze智能助手搭建过程中的问题请教
  • ¥15 12864只亮屏 不显示汉字