background image
string addcslashes(string str, string charlist):第 1 个参数 str 为待操作的原始字符串,第 2 个参数 charlist
说明需要在原始串的哪些字符前加上字符
‘\’。
string stripcslashes(string str):去掉字符串中的‘\’。
二者的使用参考下面代码。
1
<!--加入转义字符:addcslashes.php-->
2
<?php
3
$init_str = "select * from Books where name = 'PHP 手册'";
4
echo $init_str."#<br>";
5
$new_str = addcslashes($init_str,"'");
6
echo $new_str."#<br>";
7
$init_str2 = stripcslashes($new_str);
8
echo $init_str2."#<br>";
9
?>
代码在第
5 行在$init_str 中的‘’’前加上了‘\’,又在第 9 行将其去掉。
3.1.3 生成 HTML 元素
HTML 元素的书写非常麻烦,下面简单列出一些常用字符在 HTML 中的表示方式。
'&':'&amp;'
双引号
‘"’:'&quot;'