PHP addslashes() 函數
PHP addslashes() 函數用于返回一個帶有斜杠的引號字符串。愛掏網 - it200.com它適用于以下一些字符:
- 單引號 (
'
) - 雙引號 (
"
) - 反斜杠 (
\
) - NUL(
NUL
字節)
string addslashes ( string $str );
參數 | 描述 | 必需/可選 |
---|---|---|
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()的用例是在一個字符串中轉義上述字符,該字符串將由PHP進行評估:
示例4
<?php
str = "Is The Father of PHP'Rasmus?";
//Is The Father of PHP\'Rasmus?
echo addslashes(str);
?>
輸出:
Is The Father of PHP\'Rasmus?
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。