PHP addslashes() 函數(shù)
PHP addslashes() 函數(shù)用于返回一個(gè)帶有斜杠的引號(hào)字符串。愛掏網(wǎng) - it200.com它適用于以下一些字符:
- 單引號(hào) (
'
) - 雙引號(hào) (
"
) - 反斜杠 (
\
) - NUL(
NUL
字節(jié))
string addslashes ( string $str );
參數(shù) | 描述 | 必需/可選 |
---|---|---|
string | String to be escaped | 必需 |
示例1
<?php
str = 'What does "WHO" mean?';
echo "Your string is :".str;
echo "<br>"."By using addslashes() function the result is".addslashes($str);
?>
輸出:
Your string is :What does "WHO" mean?
By using addslashes() function the result isWhat does \"WHO\" mean?
示例2
<?php
str = "Who's the father of PHP?";
echostr . " This is not safe in a database query.<br>";
echo addslashes($str) . " This is safe in a database query.";
?>
輸出:
Who's the father of PHP? This is not safe in a database query.
Who\'s the father of PHP? This is safe in a database query.
示例3
<?php
str = "Wow' PHP?";
eval("echo '" . addslashes(str) . "';");
?>
輸出:
Wow' PHP?
addslashes()的用例是在一個(gè)字符串中轉(zhuǎn)義上述字符,該字符串將由PHP進(jìn)行評(píng)估:
示例4
<?php
str = "Is The Father of PHP'Rasmus?";
//Is The Father of PHP\'Rasmus?
echo addslashes(str);
?>
輸出:
Is The Father of PHP\'Rasmus?
聲明:所有內(nèi)容來自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準(zhǔn)確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。