php的addslashes,PHP addslashes()用法及代码示例
addslashes()函數(shù)是PHP中的內(nèi)置函數(shù),它返回預(yù)定義字符前帶有反斜杠的字符串。該參數(shù)中不包含任何指定的字符。
預(yù)定義的字符是:
單引號(hào)(’)
雙引號(hào)(“)
反斜杠(\)
NULL
注意:addslashes()函數(shù)不同于addcslashes()函數(shù)接受要在其之前添加斜杠的指定字符,但是addslashes()函數(shù)在參數(shù)中不接受任何字符,而是在某些指定字符之前添加斜杠。
用法:
addslashes($string)
參數(shù):addslashes()函數(shù)僅接受一個(gè)參數(shù)$string,該參數(shù)指定需要轉(zhuǎn)義的輸入字符串。我們也可以說(shuō)此參數(shù)指定了一個(gè)字符串,我們要在其中在預(yù)定義字符之前添加反斜杠。
返回值:它返回在參數(shù)中傳遞的預(yù)定義字符前面帶有反斜杠的轉(zhuǎn)義字符串。
例子:
Input:$string = "Geek's"
Output:Geek\'s
Input:$string='twinkle loves "coding"'
Output:twinkle loves \"coding\"
以下示例程序旨在說(shuō)明PHP中的addslashes()函數(shù):
程序1:
// PHP program to demonstrate the
// working of addslashes() function
// Input String
$str = addslashes('twinkle loves "coding"');
// prints the escaped string
echo($str);
?>
輸出:
twinkle loves \"coding\"
程序2:
// PHP program to demonstrate the
// working of addslashes() function
// Input String
$str = addslashes("Geek's");
// prints the escaped string
echo($str);
?>
輸出:
Geek\'s
總結(jié)
以上是生活随笔為你收集整理的php的addslashes,PHP addslashes()用法及代码示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 《PowerMock实战手册》读书笔记及
- 下一篇: android发送网络请求没反应,And