Discuz教程网

【转】php与html页面交互的函数集合

[复制链接]
authicon dly 发表于 2012-10-20 10:37:21 | 显示全部楼层 |阅读模式
1,stripslashes  addslashes
字符串的转义操作vs取消转义
form表里面提交的字符串将一些字符,比如’,”,\等自动添加\转义成为\’,\”,\\,可以使用函数
string stripslashes ( string str )
与此相反,添加转义\字符,可以使用string addslashes ( string str )
2,htmlentities    htmlspecialchars  html_entity_decode   htmlspecialchars_decode()
显示html和js代码vs执行代码
有些用户添加一些js代码,然而我们不希望他们执行,仅仅让他们显示,可以使用函数
string htmlentities ( string string [, int quote_style [, string charset]] )
string htmlspecialchars ( string string [, int quote_style [, string charset]] )
作用如下:



  1. ‘&’ (ampersand) becomes ‘&’
  2. ‘”‘ (double quote) becomes ‘"’ when ENT_NOQUOTES is not set.
  3. ”’ (single quote) becomes ”’ only when ENT_QUOTES is set.
  4. ‘<’ (less than) becomes ‘&lt;’
  5. ‘>’ (greater than) becomes ‘&gt;’
复制代码

htmlentities() 函数把字符转换为 HTML 实体。

htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体。预定义的字符是:

  1. & (和号) 成为 &amp;
  2. ” (双引号) 成为 &quot;
  3. ‘ (单引号) 成为 &#039;
  4. < (小于) 成为 &lt;
  5. > (大于) 成为 &gt;
复制代码

如果要执行,可以执行相反的函数,如下
html_entity_decode() 函数把 HTML 实体转换为字符。
html_entity_decode() 是 htmlentities() 的反函数。
htmlspecialchars_decode() 函数把一些预定义的 HTML 实体转换为字符。会被解码的 HTML 实体是:

  1. &amp; 成为 & (和号)
  2. &quot; 成为 ” (双引号)
  3. &#039; 成为 ‘ (单引号)
  4. &lt; 成为 < (小于)
  5. &gt; 成为 > (大于)
复制代码

3.strip_whitespace    strip_tags   
strip_tags() 函数剥去 HTML、XML 以及 PHP 的标签。
strip_whitespace() 函数返回已删除 PHP 注释以及空白字符的源代码文件。该函数对于检测脚本中的实际代码量很有用。
sleep()                                  //让程序睡上一会,单位秒
usleep()                                //让程序睡上一会,单位微秒
similar_text()                         //计算字符串相似度 is_numeric –   检测变量是否为数字或数字字符串



上一篇:1314学习网签到记录贴-2012年10月20日
下一篇:流畅配合 病为球队雪上加霜
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-8-2 15:06

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表