[英]More slashes when using mysql_real_escape_string
I'm a little confused with mysql_real_escape_string()
function, 我对
mysql_real_escape_string()
函数有点困惑,
I have this array below and filtering it with mysql_real_escape_string()
function, 我在下面有这个数组并用
mysql_real_escape_string()
函数过滤它,
$postFields = array('company', 'type');
$postArray = array();
foreach($postFields as $postVal){
$_POST[$postVal] = array_map("mysql_real_escape_string", $_POST[$postVal]);
$postArray[$postVal] = $_POST[$postVal];
}
so the results is like this, 所以结果是这样的,
Array
(
[type] => Array
(
[0] => CD
)
[code] => Array
(
[0] => \\\'\\\' OR \\\'\\\'
)
)
but when I want to use it single like this, 但是当我想单独使用它时,
echo mysql_real_escape_string($postArray['company'][0]);
I'm getting more slashes, like this, 我得到更多的斜线,像这样,
\\\\\\\'\\\\\\\' OR \\\\\\\'\\\\\\\'
Any reason for it, or I just do something wrong. 任何理由,或者我只是做错了什么。
In the code you provide, you're escaping the string twice: 在您提供的代码中,您将两次转义字符串:
$postFields = array('company', 'type');
$postArray = array();
foreach($postFields as $postVal){
$_POST[$postVal] = array_map("mysql_real_escape_string", $_POST[$postVal]);
$postArray[$postVal] = $_POST[$postVal];
}
echo mysql_real_escape_string($postArray['company'][0]);
Each time you escape the string, all of the backslashes get escaped into two backslashes. 每次转义字符串时,所有反斜杠都会转义为两个反斜杠。 Be careful to only escape each string once.
小心只能逃脱每个字符串一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.