亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php addslashes 函數(shù)詳細(xì)分析說明

 更新時間:2009年06月23日 21:38:29   作者:  
PHP 中的 addslashes 函數(shù) addslashes -- 字符串加入斜線。
語法: string addslashes(string str);
內(nèi)容說明
本函數(shù)使需要讓數(shù)據(jù)庫處理的字符串中引號的部份加上斜線,以供數(shù)據(jù)庫查詢 (query) 能順利運(yùn)作。這些會被改的字符包括單引號 (')、雙引號 (")、反斜線 backslash (\) 以及空字符 NUL (the null byte)。
================================================================
1,表單提交中addslashes的表現(xiàn)。
首先要看get_magic_quotes_gpc()的值,一般為 1 。這時候從 <TEXTAREA> 提交的內(nèi)容會自動加上斜線。
比如輸入 ' 變成 \' , " 變成 \" , \ 變成 \\
例子:
PHP代碼:
復(fù)制代碼 代碼如下:

<html><head><title>test</title></head>
<body>
<FORM action="" method=post>
<TEXTAREA name=message rows="18" cols="55" >default text</TEXTAREA>
<INPUT type=submit value=Submit name=submit></FORM>
<?php
echo get_magic_quotes_gpc().
" A ".$_POST['message'].
" B ".stripslashes($_POST['message']);
?>
</body></html>

輸入:include('/home/me/myfile');
輸出:1 A include(\'/home/me/myfile\'); B include('/home/me/myfile');
總結(jié):get_magic_quotes_gpc()等于1的情況下,如果不輸入數(shù)據(jù)庫,那你得到的結(jié)果是加了斜線的。
2,提交輸入數(shù)據(jù)庫時addslashes的表現(xiàn)。
例子:
PHP代碼:
復(fù)制代碼 代碼如下:

<html><head><title>test</title></head>
<body>
<FORM action="" method=post>
<TEXTAREA name=message rows="18" cols="55" >default text</TEXTAREA>
<INPUT type=submit value=Submit name=submit></FORM>
<?php
require_once('includes/common.php');
$db->query("INSERT INTO `testtable` ( id , content ) VALUES ('1' , '".$_POST['message']."')");
$query=$db->query("select * from `testtable` where `id`= 1;");
$Result=$db->fetch_array($query);
echo get_magic_quotes_gpc().
" A ".$_POST['message'].
" B ".$Result['content'];
?>
</body></html>

輸入:include('/home/me/myfile');
輸出:1 A include(\'/home/me/myfile\'); B include('/home/me/myfile');
總結(jié):get_magic_quotes_gpc()等于1的情況下,如果輸入數(shù)據(jù)庫后,再從數(shù)據(jù)庫直接讀取的時候,你不做任何修改就可以得到輸入的字符串。
3, get_magic_quotes_gpc()
get_magic_quotes_gpc()在服務(wù)器是的設(shè)置是不能runtime修改的,也就是說,你必須在你的網(wǎng)頁代碼中預(yù)先考慮好不同的情況,不然,當(dāng)你提交數(shù)據(jù)的時候,你還不知道服務(wù)器給你加了斜線沒有。以下兩個網(wǎng)上流行的函數(shù)可能是大家需要的,個人喜歡第二個:
PHP代碼:
復(fù)制代碼 代碼如下:

function my_addslashes( $message ){
if(get_magic_quotes_gpc()== 1 ){
return $message;
}else{
if(is_array($message)==true){
while(list($key,$value)=each($message)){
$message[$key]=my_addslashes($value);
}
return $message;
}else{
return addslashes($message);
}
}
}

PHP代碼: 
復(fù)制代碼 代碼如下:

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

簡單的解釋就是,如果get_magic_quotes_gpc()等于 1 (服務(wù)器默認(rèn)設(shè)置為 1 ),那我們的字符串是可以直接入庫的,不修改。不然,我們才用addslashes函數(shù)。

相關(guān)文章

  • php adodb分頁實現(xiàn)代碼

    php adodb分頁實現(xiàn)代碼

    php利用adodb分頁實現(xiàn)代碼
    2009-03-03
  • 高亮度顯示php源代碼

    高亮度顯示php源代碼

    高亮度顯示php源代碼...
    2006-10-10
  • PHP腳本的10個技巧(3)

    PHP腳本的10個技巧(3)

    PHP腳本的10個技巧(3)...
    2006-10-10
  • 最新評論