总结PHP的引号和反斜杠问题
bob 发布于 February 26, 2006 15:39
1. magic_quotes_gpc=on:
\ => \\
' => \'
" => \"
2. 当 \' 、\" 插入数据库时,字符并没有变化,仍然为 ' 和 " 。因此读出时无需再次stripslashes。
例外:magic_quotes_runtime=on时。
3. preg_replace的pattern中使用 /e 修正符,则replacement传递到callback函数中的情形为:
\ => \
' => '
" => \"
4. 从数据库中读取,当magic_quotes_runtime=off时,似乎 \ => 空 ?
总结:引号和反斜杠的问题很复杂,而且因各服务器的设置不同而千变万化。
现在我的解决方法是
\ => & #92;
引号则用 htmlspecialchars ,quote_style设置为 ENT_QUOTES。
希望SP1版本中贴代码的问题能够解决。
测试:
\ => \\
' => \'
" => \"
2. 当 \' 、\" 插入数据库时,字符并没有变化,仍然为 ' 和 " 。因此读出时无需再次stripslashes。
例外:magic_quotes_runtime=on时。
3. preg_replace的pattern中使用 /e 修正符,则replacement传递到callback函数中的情形为:
\ => \
' => '
" => \"
4. 从数据库中读取,当magic_quotes_runtime=off时,似乎 \ => 空 ?
总结:引号和反斜杠的问题很复杂,而且因各服务器的设置不同而千变万化。
现在我的解决方法是
\ => & #92;
引号则用 htmlspecialchars ,quote_style设置为 ENT_QUOTES。
希望SP1版本中贴代码的问题能够解决。
测试:
<?php
error_reporting(E_ALL);
/* 加入重定向以得到标准错误输出 stderr。 */
$handle = popen('/path/to/spooge 2>&1', 'r');
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
pclose($handle);
?>
error_reporting(E_ALL);
/* 加入重定向以得到标准错误输出 stderr。 */
$handle = popen('/path/to/spooge 2>&1', 'r');
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
pclose($handle);
?>
Peter
用下面的函数入库就一定没有问题
function my_addslashes($data){
if(!get_magic_quotes_gpc()) {
return is_array($data)?array_map(\'AddSlashes\',$data):addslashes($data);
} else {
Return $data;
}
}
原来对这个问题我也很头大,最后总算弄明白了,总结了一下,Bob 有空可以看一看:
http://www.yideu.com/web/bbs/viewthread.php?tid=200
function my_addslashes($data){
if(!get_magic_quotes_gpc()) {
return is_array($data)?array_map(\'AddSlashes\',$data):addslashes($data);
} else {
Return $data;
}
}
原来对这个问题我也很头大,最后总算弄明白了,总结了一下,Bob 有空可以看一看:
http://www.yideu.com/web/bbs/viewthread.php?tid=200
分页: 1/1
1
1



if(!get_magic_quotes_gpc()) {
return is_array($data)?array_map('AddSlashes',$data):addslashes($data);
} else {
Return $data;
}
}
怎么用?