您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 信息化管理 > PHP动态网页开发中常用的一些函数
PHP动态网页开发中常用的一些函数在php网页的开头加入以下以下为引用的内容:?$time_start=getmicrotime();functiongetmicrotime(){list($usec,$sec)=explode(,microtime());return((float)$usec+(float)$sec);}?然后到最后加入以下代码以下为引用的内容:?$time_end=getmicrotime();printf([页面执行时间:%.2f毫秒]\n\n,($time_end-$time_start)*1000);?$file=fopen($filename,'r')ordie(抱歉,无法打开:$filename);or在这里是这样理解的,因为在php中并不区分数据类型,所以$file既可以是int也可以bool,所以这样的语句不会报错。但其处理过程可能有些朋友不大明白。其实在大多数的语言中,boolorbool这样的语句中,如果前一个值为真后一个值就不会再判断了。这里也是的,所以如果fopen函数执行正确的话,会返回一个大于0的int值(这其实就是“真”),后面的语句就不会执行了。如果fopen函数执行失败,就会返回false,那么就会判断后面的表达式是否为真了。结果执行了die()之后,不管返回什么,程序都已经停止执行了,并且显示指定的出错信息,也就达到了调试的目的。php复选框的问题以下为引用的内容:formname=form1method=postaction=d.phpinputtype=checkboxname=checkbox[]value=111111inputtype=checkboxname=checkbox[]value=222222inputtype=checkboxname=checkbox[]value=3333333inputtype=checkboxname=checkbox[]value=44444444inputtype=checkboxname=checkbox[]value=5555555inputtype=checkboxname=checkbox[]value=66666666inputtype=submitname=submitvalue=提交/formd.php以下为引用的内容:?$fd=$_post['checkbox'];for($i=0;$i(sizeof($fd));$i++){$newhpt=$newhpt.$fd[$i].,;}echo$newhpt.br;?php代码中函数前面的@是什么意思?@的作用是忽略调用该函数时产生的错误信息。php中日期相加的问题以下为引用的内容:?$fd=$_post['checkbox'];for($i=0;$i(sizeof($fd));$i++){$newhpt=$newhpt.$fd[$i].,;}echo$newhpt.br;?关于php水印的问题以下为引用的内容:?php//读取目标文件$im=imagecreatefromjpeg(1[2].jpg);//设定混合模式imagealphablending($im,true);//读取水印$im2=imagecreatefrompng(watermark.png);//下面是我写的字,可以不看//$color=imagecolorallocate($im2,0,0,0);//imagestring($im2,12,1,1,iloveujingjing,$color);//字结束//拷贝水印到目标文件imagecopy($im,$im2,5,5,0,0,220,34);//输出,可以输出到文件里imagejpeg($im);imagedestroy($im);imagedestroy($im1);??php$im=imagecreatefromjpeg(1[2].jpg);//$im=imagecreatefromgif(eee.gif);//$im=imagecreatefrompng(1[2].png);$black=imagecolorallocate($im,0,140,76);$red=imagecolorallocate($im,255,0,0);$string=chr(0xe5).chr(0xae).chr(0x89).chr(0xe5).chr(0xba).chr(0x86).chr(0xe6).chr(0x88).chr(0xbf).chr(0xe4).chr(0xba).chr(0xa7).chr(0xe7).chr(0xbd).chr(0x91);//imagestring($im,12,10,10,$string,$red);imagettftext($im,20,0,4,30,$red,fzdhtjw.ttf,$string);imagepng($im);imagedestroy($im);??//这个函数是把汉字转换成utf-8后,就可以在gd中使用了!functiongb2utf8($gb){if(!trim($gb))return$gb;$filename=gb2312.txt\;$tmp=file($filename);$codetable=array();while(list($key,$value)=each($tmp))$codetable[hexdec(substr($value,0,6))]=substr($value,7,6);$utf8=\\;while($gb){if(ord(substr($gb,0,1))127){$this=substr($gb,0,2);$gb=substr($gb,2,strlen($gb));$utf8.=u2utf8(hexdec($codetable[hexdec(bin2hex($this))-0x8080]));}else{$gb=substr($gb,1,strlen($gb));$utf8.=u2utf8(substr($gb,0,1));}}$ret=\\;for($i=0;$istrlen($utf8);$i+=3)$ret.=chr(substr($utf8,$i,3));return$ret;}functionu2utf8($c){for($i=0;$icount($c);$i++)$str=\\;if($c0x80){$str.=$c;}elseif($c0x800){$str.=(0xc0|$c6);$str.=(0x80|$c&0x3f);}elseif($c0x10000){$str.=(0xe0|$c12);$str.=(0x80|$c6&0x3f);$str.=(0x80|$c&0x3f);}elseif($c0x200000){$str.=(0xf0|$c18);$str.=(0x80|$c12&0x3f);$str.=(0x80|$c6&0x3f);$str.=(0x80|$c&0x3f);}return$str;}header(\content-type:image/gif\);$im=imagecreate(400,300);$bkg=imagecolorallocate($im,0,0,0);$clr=imagecolorallocate($im,255,255,255);$fnt=\wb.t(\gb2utf8.php\);$str=gb2utf8(\中国\);imagettftext($im,20,0,10,20,$clr,$fnt,$str);imagegif($im);imagedestroy($im);?以下为引用的内容:?php//对javascript和select部件的结合运用//在写程序的过程,我想实现在select对象选中选项后,//不需要提交按钮,而直接触发动作,且在动作发生后//的页面中要保持所选择的选项。经过形容,终于通过//使用javascript及select对象的onchange属性及//value值而实现了这种功能。//代码如下(文件名为test.php):switch($mon){case'':echo'请选择您的星座:';break;case'1':echo'您的星座是水瓶座';break;case'2':echo'您的星座是双鱼座';break;case'3':echo'您的星座是白羊座';break;case'4':echo'您的星座是金牛座';break;case'5':echo'您的星座是双子座';break;case'6':echo'您的星座是巨蟹座';break;case'7':echo'您的星座是狮子座';break;case'8':echo'您的星座是处女座';break;case'9':echo'您的星座是天平座';break;case'10':echo'您的星座是天蝎座';break;case'11':echo'您的星座是射手座';break;case'12':echo'您的星座是魔蝎座';break;default:break;}?formname=form1selectname=month_selectonchange=#location.href=this.options[this.selectedindex].valueoption--请选择你的星座--/optionoptionvalue=test.php?mon=1?phpif($mon==1)echoselected;?水瓶座/optionoptionvalue=test.php?mon=2?phpif($mon==2)echoselected;?双鱼座/optionoptionvalue=test.php?mon=3?phpif($mon==3)echoselected;?白羊座/optionoptionvalue=test.php?mon=4?phpif($mon==4)echoselected;?金牛座/optionoptionvalue=test.php?mon=5?phpif($mon==5)echoselected;?双子座/optionoptionvalue=test.php?mon=6?phpif($mon==6)echoselected;?巨蟹座/optionoptionvalue=test.php?mon=7?phpif($mon==7)echoselected;?狮子座/optionoptionvalue=test.php?mon=8?phpif($mon==8)echoselected;?处女座/optionoptionvalue=test.php?mon=9?phpif($mon==9)echoselected;?天平座/optionoptionvalue=test.php?mon=10?phpif($mon==10)echoselected;?天蝎座/optionoptionvalue=test.php?mon=11?phpif($mon==11)echoselected;?射手座/optionoptionvalue=test.php?mon=12?phpif($mon==12)echoselected;?魔蝎座/option/select/form?$uploadimgurl=mag/;$showdatefilename=strftime(%y%m%d%h%m%s);if($_get[up]==up){$uploadimgname=$_fi
本文标题:PHP动态网页开发中常用的一些函数
链接地址:https://www.777doc.com/doc-2850399 .html