下面只提供几个简单常用的函数,chop执行去除空格处理,get_html_translation_table返回转化列表到变量,定义包括HTML编码的字符串htmlentities,htmlspecialchars_decode 定义包含HTML特殊字符的字符串,nl2br quotemeta rtrim等.
定义和用法:chop() 函数从字符串的末端开始删除空白字符或其他预定义字符,该函数的 rtrim() 函数的别名.
语法:chop(string,charlist),代码如下:
- $str="i'm a teacher ";
- $result=chop($str);
- echo $result;
定义和用法:get_html_translation_table() 函数返回被 htmlentities() 和 htmlspecialchars() 函数使用的翻译表.
语法:get_html_translation_table(function,quotestyle),代码如下:
- /*/
- $trans=get_html_translation_table(html_entities);
- print_r($trans);
- $str="hallo & <frau> & krmer";
- $encoded=strtr($str,$trans);
- echo $encoded;
-
-
- $str="a 'quote' is <b>bold</b>";
- echo htmlentities($str);
- echo htmlentities($str, ent_quotes);
-
-
- $str='<p>this -> "</p>';
- echo htmlspecialchars_decode($str);
- echo "<br>";
- echo htmlspecialchars_decode($str,ent_noquotes);
-
-
-
- $str="cat isn't n dog";
- $result=nl2br($str);
- echo $result;
-
-
-
- $str="hello world.(can you hear me?)";
- $result=quotemeta($str);
- echo $result;
-
-
-
- $str="hello world ";
- $result=rtrim($str);
- echo $result;
|