addslashes()函數是PHP中的內置函數,它返回預定義字符前帶有反斜杠的字符串。該參數中不包含任何指定的字符。
預定義的字符是:
- 單引號(’)
- 雙引號(“)
- 反斜杠(\)
- NULL
注意:addslashes()函數不同於addcslashes()函數接受要在其之前添加斜杠的指定字符,但是addslashes()函數在參數中不接受任何字符,而是在某些指定字符之前添加斜杠。
用法:
addslashes($string)
參數:addslashes()函數僅接受一個參數$string,該參數指定需要轉義的輸入字符串。我們也可以說此參數指定了一個字符串,我們要在其中在預定義字符之前添加反斜杠。
返回值:它返回在參數中傳遞的預定義字符前麵帶有反斜杠的轉義字符串。
例子:
Input:$string = "Geek's" Output:Geek\'s Input:$string='twinkle loves "coding"' Output:twinkle loves \"coding\"
以下示例程序旨在說明PHP中的addslashes()函數:
程序1:
<?php
// 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
// PHP program to demonstrate the
// working of addslashes() function
// Input String
$str = addslashes("Geek's");
// prints the escaped string
echo($str);
?>輸出:
Geek\'s
參考:
http://php.net/manual/en/function.addslashes.php
相關用法
- p5.js nf()用法及代碼示例
- PHP Ds\Set get()用法及代碼示例
- p5.js max()用法及代碼示例
- PHP abs()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP exp()用法及代碼示例
- p5.js nfc()用法及代碼示例
- PHP sin( )用法及代碼示例
- p5.js box()用法及代碼示例
- PHP Ds\Set sum()用法及代碼示例
- p5.js value()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 PHP | addslashes() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
