在每个双引号(")前添加反斜杠:
<?php
$str = addslashes('Shanghai is the "biggest" city in China.');
echo($str);
?>
addslashes() 函数返回在预定义字符之前添加反斜杠的字符串。
预定义字符是:
addslashes(string)
参数 | 描述 |
---|---|
string | 必需。规定要转义的字符串。 |
返回值: | 返回已转义的字符串。 |
PHP 版本: | 4+ |
向字符串中的预定义字符添加反斜杠:
<?php
$str = "Who's Bill Gates?";
echo $str . " This is not safe in a database query.<br>";
echo addslashes($str) . " This is safe in a database query.";
?>
©2020 IT自习室京ICP备20010815号