ImageVerifierCode 换一换
格式:DOCX , 页数:8 ,大小:19.91KB ,
资源ID:10957666      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10957666.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(php开发中常用函数总结.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

php开发中常用函数总结.docx

1、php开发中常用函数总结php开发中常用函数总结 1.获取IP2.时间的增加3.检查日期是否合法日期4.时间比较函数,返回两个日期相差几秒、几分钟、几小时或几天5.PHP重定向6.获取访问者浏览器7.获取访问者操作系统8.文件格式类9.php生成excel文档10.时间比较问题11.提取页面和浏览器提交的变量,作用相当于使PHP.INI开了全局变量12.读取文件函数13.写入文件函数14.页面快速转向15.产生随机字符串函数16.截取一定长度的字符串(该函数对GB2312使用有效)17.取得客户端IP地址18.判断邮箱地址19.分页(两个函数配合使用)20.获取新插入数据的ID21.获得当前的

2、脚本网址22.把全角数字转为半角数字23.去除HTML标记24.相对路径转化成绝对路径26.取得所有链接27.HTML表格的每行转为CSV格式数组28.将HTML表格的每行每列转为数组,采集表格数据29.返回字符串中的所有单词 $distinct=true 去除重复30.打印出为本PHP项目做出贡献的人员的清单<? function GetIP() /获取IP if ($_SERVERHTTP_X_FORWARDED_FOR) $ip = $_SERVERHTTP_X_FORWARDED_FOR; else if ($_SERVERHTTP_CLIENT_IP) $ip = $_SERV

3、ERHTTP_CLIENT_IP; else if ($_SERVERREMOTE_ADDR) $ip = $_SERVERREMOTE_ADDR; else if (getenv(HTTP_X_FORWARDED_FOR) $ip = getenv(HTTP_X_FORWARDED_FOR); else if (getenv(HTTP_CLIENT_IP) $ip = getenv(HTTP_CLIENT_IP); else if (getenv(REMOTE_ADDR) $ip = getenv(REMOTE_ADDR); else $ip = Unknown; return $ip;?&

4、gt;downsource<?phpfunction DateAdd($date, $int, $unit = d) /时间的增加(还可以改进成时分秒都可以增加,有时间再补上) $dateArr = explode(-, $date); $value$unit = $int; return date(Y-m-d, mktime(0,0,0, $dateArr1 + $valuem, $dateArr2 + $valued, $dateArr0 + $valuey);function GetWeekDay($date) /计算出给出的日期是星期几 $dateArr = explode(-,

5、 $date); return date(w, mktime(0,0,0,$dateArr1,$dateArr2,$dateArr0);?>downsource<?function check_date($date) /检查日期是否合法日期 $dateArr = explode(-, $date); if (is_numeric($dateArr0) && is_numeric($dateArr1) && is_numeric($dateArr2) return checkdate($dateArr1,$dateArr2,$dateArr0); re

6、turn false;function check_time($time) /检查时间是否合法时间 $timeArr = explode(:, $time); if (is_numeric($timeArr0) && is_numeric($timeArr1) && is_numeric($timeArr2) if ($timeArr0 >= 0 && $timeArr0 <= 23) && ($timeArr1 >= 0 && $timeArr1 <= 59) && ($t

7、imeArr2 >= 0 && $timeArr2 <= 59) return true; else return false; return false;function DateDiff($date1, $date2, $unit = ) /时间比较函数,返回两个日期相差几秒、几分钟、几小时或几天 switch ($unit) case s: $dividend = 1; break; case i: $dividend = 60; break; case h: $dividend = 3600; break; case d: $dividend = 86400

8、; break; default: $dividend = 86400; $time1 = strtotime($date1); $time2 = strtotime($date2); if ($time1 && $time2) return (float)($time1 - $time2) / $dividend; return false;?>downsourcePHP重定向<?方法一:header(Location: index.php);方法二:echo <scrpt>window.location =$PHP_SELF;</scrpt&g

9、t;方法三:echo <META HTTP-EQUIV=Refresh CONTENT=0; URL=index.php>?>downsource获取访问者浏览器<?function browse_infor()$browser=;$browserver=;$Browsers =array(Lynx,MOSAIC,AOL,Opera,JAVA,MacWeb,WebExplorer,OmniWeb);$Agent = $GLOBALSHTTP_USER_AGENT;for ($i=0; $i<=7; $i+)if (strpos($Agent,$Browsers$i

10、)$browser = $Browsers$i;$browserver =;if (ereg(Mozilla,$Agent) && !ereg(MSIE,$Agent)$temp =explode(, $Agent); $Part=$temp0;$temp =explode(/, $Part); $browserver=$temp1;$temp =explode( ,$browserver); $browserver=$temp0;$browserver =preg_replace(/(d.+)/,1,$browserver);$browserver = $browserver

11、;$browser = Netscape Navigator;if (ereg(Mozilla,$Agent) && ereg(Opera,$Agent)$temp =explode(, $Agent); $Part=$temp1;$temp =explode(), $Part); $browserver=$temp1;$temp =explode( ,$browserver);$browserver=$temp2;$browserver =preg_replace(/(d.+)/,1,$browserver);$browserver = $browserver;$browse

12、r = Opera;if (ereg(Mozilla,$Agent) && ereg(MSIE,$Agent)$temp = explode(, $Agent); $Part=$temp1;$temp = explode(;,$Part); $Part=$temp1;$temp = explode( ,$Part);$browserver=$temp2;$browserver =preg_replace(/(d.+)/,1,$browserver);$browserver = $browserver;$browser = Internet Explorer;if ($brows

13、er!=)$browseinfo = $browser$browserver;else$browseinfo = Unknown;return $browseinfo;/调用方法$browser=browseinfo() ;直接返回结果?>downsource获取访问者操作系统<?function osinfo() $os=;$Agent = $GLOBALSHTTP_USER_AGENT;if (eregi(win,$Agent) && strpos($Agent, 95) $os=Windows 95;elseif (eregi(win 9x,$Agent) &

14、amp;& strpos($Agent, 4.90) $os=Windows ME;elseif (eregi(win,$Agent) && ereg(98,$Agent) $os=Windows 98;elseif (eregi(win,$Agent) && eregi(nt 5.0,$Agent) $os=Windows 2000;elseif (eregi(win,$Agent) && eregi(nt,$Agent) $os=Windows NT;elseif (eregi(win,$Agent) && eregi

15、(nt 5.1,$Agent) $os=Windows XP;elseif (eregi(win,$Agent) && ereg(32,$Agent) $os=Windows 32;elseif (eregi(linux,$Agent) $os=Linux;elseif (eregi(unix,$Agent) $os=Unix;elseif (eregi(sun,$Agent) && eregi(os,$Agent) $os=SunOS;elseif (eregi(ibm,$Agent) && eregi(os,$Agent) $os=IBM O

16、S/2;elseif (eregi(Mac,$Agent) && eregi(PC,$Agent) $os=Macintosh;elseif (eregi(PowerPC,$Agent) $os=PowerPC;elseif (eregi(AIX,$Agent) $os=AIX;elseif (eregi(HPUX,$Agent) $os=HPUX;elseif (eregi(NetBSD,$Agent) $os=NetBSD;elseif (eregi(BSD,$Agent) $os=BSD;elseif (ereg(OSF1,$Agent) $os=OSF1;elseif

17、(ereg(IRIX,$Agent) $os=IRIX;elseif (eregi(FreeBSD,$Agent) $os=FreeBSD;if ($os=) $os = Unknown;return $os;/调用方法$os=os_infor() ;?>downsource文件格式类<?$mime_types = array(gif => image/gif,jpg => image/jpeg,jpeg => image/jpeg,jpe => image/jpeg,bmp => image/bmp,png => image/png,tif =

18、> image/tiff,tiff => image/tiff,pict => image/x-pict,pic => image/x-pict,pct => image/x-pict,tif => image/tiff,tiff => image/tiff,psd => image/x-photoshop,swf => application/x-shockwave-flash,js => application/x-javascrpt,pdf => application/pdf,ps => application/p

19、ostscrpt,eps => application/postscrpt,ai => application/postscrpt,wmf => application/x-msmetafile,css => text/css,htm => text/html,html => text/html,txt => text/plain,xml => text/xml,wml => text/wml,wbmp => image/vnd.wap.wbmp,mid => audio/midi,wav => audio/wav,mp3

20、 => audio/mpeg,mp2 => audio/mpeg,avi => video/x-msvideo,mpeg => video/mpeg,mpg => video/mpeg,qt => video/quicktime,mov => video/quicktime,lha => application/x-lha,lzh => application/x-lha,z => application/x-compress,gtar => application/x-gtar,gz => application/x-g

21、zip,gzip => application/x-gzip,tgz => application/x-gzip,tar => application/x-tar,bz2 => application/bzip2,zip => application/zip,arj => application/x-arj,rar => application/x-rar-compressed,hqx => application/mac-binhex40,sit => application/x-stuffit,bin => application

22、/x-macbinary,uu => text/x-uuencode,uue => text/x-uuencode,latex=> application/x-latex,ltx => application/x-latex,tcl => application/x-tcl,pgp => application/pgp,asc => application/pgp,exe => application/x-msdownload,doc => application/msword,rtf => application/rtf,xls =

23、> application/vnd.ms-excel,ppt => application/vnd.ms-powerpoint,mdb => application/x-msaccess,wri => application/x-mswrite,);?>downsourcephp生成excel文档<?header(Content-type:application/vnd.ms-excel);header(Content-Disposition:filename=test.xls);echo test1t;echo test2tn;echo test1t;ec

24、ho test2tn;echo test1t;echo test2tn;echo test1t;echo test2tn;echo test1t;echo test2tn;echo test1t;echo test2tn;/改动相应文件头就可以输出.doc .xls等文件格式了?>downsource时间比较问题举一个简单例子说明:比如一个论坛对当天发表的贴子用new图片标记一下。方法一:<?/$db->rows$idate中为数据库中datetime字段值.$today=time();$theDay=date(Y-m-d H:i:s,$today-24*3600);$new

25、Tag=$db->rows$idate>=$theDay?<img src=./image/newinfor.gif>:;/方法二:$newTag=$db->rows$idate>=date(Y-m-d 00:00:00)?<img src=./image/newinfor.gif>:;?>downsource/提取页面和浏览器提交的变量,作用相当于使PHP.INI开了全局变量<?extract($_SERVER, EXTR_SKIP);extract($_SESSION, EXTR_SKIP);extract($_POST, EXT

26、R_SKIP);extract($_FILES, EXTR_SKIP);extract($_GET, EXTR_SKIP);extract($_ENV, EXTR_SKIP);?>downsource/读取文件函数<?function readfromfile($file_name) if (file_exists($file_name) $filenum=fopen($file_name,r);flock($filenum,LOCK_EX);$file_data=fread($filenum, filesize($file_name);rewind($filenum);fclos

27、e($filenum);return $file_data;?>downsource/写入文件函数<?function writetofile($file_name,$data,$method=w) $filenum=fopen($file_name,$method);flock($filenum,LOCK_EX);$file_data=fwrite($filenum,$data);fclose($filenum);return $file_data;?>downsource/页面快速转向<?function turntopage($url=index.php,$inf

28、o = 页面转向中.,$second=2)print <html>n<head>n<title>页面转向中.</title>n;print <meta http-equiv=refresh content=$second;url=$url>n;print <style type=text/css>n<!-n;print td font-family: Verdana, Arial;font-size: 12pxn;print A COLOR: #000000; TEXT-DECORATION: nonen;print

29、 ->n</style>n;print </head>n<body>n;print <table width=100% border=0 align=center>n;print <tr>n;print <td height=200> </td>n;print </tr>n;print <tr>n;print <td align=center>n;print <table width=60% border=0 cellpadding=8 bgcolor=#AA9F

30、FF>n;print <tr>n;print <td height=30 align=center>页面转向提示信息</td>n;print </tr>n;print <tr>n;print <td align=center>$info</td>n;print </tr>n;print <tr>n;print <td align=center>n;print <a href=$url>如果你的浏览器不支持自动跳转,请按这里</a></td>n;print

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1