php (hypertext preprocessor)是一种 html 内嵌式的语言,也是目前比较流行的网页编程语言。它支持的后端数据库种类凡多,几乎含盖了当前的所有数据库系统。同时它包含了一般语言有的数学运算、时间处理、文件系统、字符串处理、行程处理等功能,再加上它是免费的系统,使得成本与效益比,几乎等于无限大。
下面是我在用php做网站时,总结出一些小技巧,拿出来飨以大家。
| 1、判断某个函数是否被支持 |
| if(!function_exists('imagecreate')) { die('这个主机目前不支持gd图形模块'); } ?> |
| 2、在字符串中把网址改成超级链接 |
| $string = "连接赛迪网http://www.cci.net.com 站点"; //注意:连接后需要有个空格或回车。 $string = eregi_replace("http://([^ ,\r\n]*)","<a href=\\0 tarrget=_blank>\\0</a>",$string); $string = eregi_replace("ftp://([^ ,\r\n]*)","<a href=\\0 target=_blank>\\0</a>",$string); print $string; ?> |
| 3、用php处理多个同名复选框 |
| 4、利用static实现表格的颜色隔行显示 |
| function getcolor() { static $colorvalue;//定义一个静态变量 if($colorvalue=="#eeeeee") $colorvalue="#f5f5f5"; else $colorvalue="#eeeeee"; return($colorvalue); } print("<table border=1>\n");//下面输出10行 for($i=0;$i<10;$i++) { $bcolor=getcolor();//换背景颜色 print("<tr bgcolor=$bcolor>\n"); print("<td>$i</td>\n"); print("</tr>"); } print("</table>\n"); ?> |
| 说明: |
| 5、在php中避免重复引用的办法 |
| if (!empty($globals['foodtails']['globaldefine'])) return; $globals['foodtails']['globaldefine'] = true; class foodtails {... }; ?> |
| 6、如何避免表单的重复提交 |
| if($lastaction>$userlastaction){ $userlastaction++; // 序列号加1 // 处理表单数据 } ?> |
| 7、下载文件的下载次数回填 |
| //连接mysql数据库代码略 $res=mysql_query("update download set downnum=(downnum+1) where id='$id'" ,$db); header("location:$filename"); ?> |
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器