一、addslashes()函数 1.addslashes()函数,是在指定的预定字符前加反斜杠。语法:addslashes(str); 2.参数是一个字符串 3.这些预定义字符有四种,是:单引号(’),双引号(”)、反斜杠(\)和NULL 4.例如: <?php $str='Who's John Adams?'; echo $str.'This is not safe in a database query.<br/>';//输出:Who's John Adams?This is not safe in a database query. echo addslashes($str).'This is safe in a database query.';//输出:Who\'s John Adams?This is sage in a database query. ?> 二、addcslashes()函数 1.addcslashes()函数,是在指定的字符前添加反斜杠。 语法:addcslashes(str,chararcters); 2.中参数str是必须的,规定要检查的字符串,而character是可选的,规定受addcslashes()影响的字符或字符范围。 3.例1: <?php $str='Hello,my name is John Adams.'; echo $str; //输出:Hello,my name is John Adams. echo addcslashes($str,'m'); //输出:Hello,\my na\me is John Ada\ms. echo addcslashes($str,'J'); //输出:Hello,my name is \John Adams. ?> 例2、 <?php $str='Hello,my name is John Adams.'; echo $str; //输出:Hello,my name is John Adams |
|