php中add函数,php中addslashes()和addclashes()函数的区别分析
1,addcslashes 函數(shù)
PHP String 函數(shù)
定義和用法
addcslashes() 函數(shù)在指定的字符前添加反斜杠。
語法
addcslashes(string,characters)
參數(shù)?描述
string?必需。規(guī)定要檢查的字符串。
characters?可選。規(guī)定受 addcslashes() 影響的字符或字符范圍。
提示和注釋
注釋:在對 0,r,n 和 t 應(yīng)用 addcslashes() 時(shí)要小心。在 PHP 中,\0,\r,\n 和 \t 是預(yù)定義的轉(zhuǎn)義序列。
例子:
復(fù)制代碼 代碼示例:
//向字符串中的特定字符添加反斜杠
$str = "Hello, my name is John Adams.";
echo $str;
echo addcslashes($str,'m');
echo addcslashes($str,'J');
?>
輸出:
Hello, my name is John Adams.
Hello, \my na\me is John Ada\ms.
Hello, my name is \John Adams.
2,addslashes函數(shù)
PHP String 函數(shù)
定義和用法
addslashes() 函數(shù)在指定的預(yù)定義字符前添加反斜杠。
這些預(yù)定義字符是:
單引號(hào) (')
雙引號(hào) (")
反斜杠 (\)
NULL
語法
addslashes(string)
參數(shù)?描述
string?必需。規(guī)定要檢查的字符串。
提示和注釋
提示:該函數(shù)可用于為存儲(chǔ)在數(shù)據(jù)庫中的字符串以及數(shù)據(jù)庫查詢語句準(zhǔn)備合適的字符串。
注釋:默認(rèn)情況下,PHP 指令 magic_quotes_gpc 為 on,對所有的 GET、POST 和 COOKIE 數(shù)據(jù)自動(dòng)運(yùn)行 addslashes()。不要對已經(jīng)被 magic_quotes_gpc 轉(zhuǎn)義過的字符串使
用 addslashes(),因?yàn)檫@樣會(huì)導(dǎo)致雙層轉(zhuǎn)義。遇到這種情況時(shí)可以使用函數(shù) get_magic_quotes_gpc() 進(jìn)行檢測。
例子:
復(fù)制代碼 代碼示例:
//向字符串中的預(yù)定義字符添加反斜杠
$str = "Who's John Adams?";
echo $str . " This is not safe in a database query.
";
echo addslashes($str) . " This is safe in a database query.";
?>
輸出:
Who's John Adams? This is not safe in a database query.
Who\'s John Adams? This is safe in a database query.
對于函數(shù)addslashes()和addclashes(),都有對應(yīng)的去除反斜杠的方法,分別為:stripcslashes函數(shù)和stripslashes函數(shù)。有興趣的朋友,也可以研究下。
總結(jié)
以上是生活随笔為你收集整理的php中add函数,php中addslashes()和addclashes()函数的区别分析的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 下载的压缩文件,php在线压缩打
- 下一篇: 动态规划算法php,php算法学习之动态