1、收藏 PHP 常用函数 shuguang , 10:13 , 代码片段 , 评论 (13) , 引用(0) , 阅读(29978) , Via 本站原创 大 | 中 | 小 = 0 “; 方法三:echo “; ? 获取访问者浏览器 获取访问者操作系统 文件格式类 image/gif, /PHP开源代码 jpg = image/jpeg, jpeg = image/jpeg, jpe = image/jpeg, bmp = image/bmp, png = image/png, tif = image/tiff, tiff = image/tiff, pict = image/x-pict,
2、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/postscrpt, eps = application/postscrpt, ai = application/postscrpt, wmf = application/x-msm
3、etafile, 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 = audio/mpeg, mp2 = audio/mpeg, avi = video/x-msvideo, mpeg = video/mpeg, mpg = video/mpeg, qt = video/quicktime, mov = vide
4、o/quicktime, lha = application/x-lha, lzh = application/x-lha, z = application/x-compress, gtar = application/x-gtar, gz = application/x-gzip, gzip = application/x-gzip, tgz = application/x-gzip, tar = application/x-tar, bz2 = application/bzip2, zip = application/zip, arj = application/x-arj, rar =
5、application/x-rar-compressed, /开源 OSPhP.COM.CN hqx = application/mac-binhex40, sit = application/x-stuffit, bin = application/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 = applica
6、tion/pgp, exe = application/x-msdownload, doc = application/msword, rtf = application/rtf, xls = application/vnd.ms-excel, ppt = application/vnd.ms-powerpoint, mdb = application/x-msaccess, wri = application/x-mswrite, ); ? php生成 excel文档 时间比较问题 举一个简单例子说明:比如一个论坛对当天发表的贴子用 new图片标记一下。 /oSPHP.COM.CN 方法一:
7、 rows$idate中为数据库中 datetime字段值. $today=time(); $theDay=date(“Y-m-d H:i:s“,$today-24*3600); $newTag=$db-rows$idate=$theDay?“:“; /开源 OSPhP.COM.CN /方法二: $newTag=$db-rows$idate=date(“Y-m-d 00:00:00“)?“:“; ? /提取页面和浏览器提交的变量,作用相当于使 PHP.INI开了全局变量 /OSPHP.COm.CN /读取文件函数 /写入文件函数 /OsPHP.COM.CN /页面快速转向 nn页面转向中n“;
8、 print “n“; /开源代码 OSPhP.COm.CN print “nnn“; print “nn“; print “n“; /开源代码OSPHP.COM.Cn print “ n“; print “ n“; print “ n“; print “ n“; print “ n“; print “ n“; print “ n“; print “ 页面转向提示信息n“; print “ n“; print “ n“; print “ $infon“; print “ n“; print “ n“; print “ n“; print “ 如果你的浏览器不支持自动跳转,请按这里n“; pri
9、nt “ n“; print “ n“; print “ n“; print “ n“; print “ n“; print “ n“; print “ n“; print “n“; print “n“; exit; ? 产生随机字符串函数 截取一定长度的字符串(该函数对 GB2312使用有效) $length) if($sss) $length=$length - 3; $addstr=# .#; /PHP开源代码 for($i = 0; $i 127) $wordscut .= $string$i.$string$i + 1; /OSPHP.COM.Cn开源 $i+; else $word
10、scut .= $string$i; return $wordscut.$addstr; return $string; ? 取得客户端 IP地址 /OSPHP.com.CN判断邮箱地址 分页(两个函数配合使用) “.$totalpage.“页“; /开源 OSPhP.COM.CN $linkNum =4; $start = ($page-round($linkNum/2)0 ? ($page-round($linkNum/2) : “1“; /OSPHP.COM.Cn开源$end = ($page+round($linkNum/2)1) $out .= “第一页 “; if($start1)
11、 /OSPHP.COm.CN $out.=“ “; for($t=$start;$t“.$t.“ “ : “$t “; /OSPHP.com.CN if($end“; if($page 获取新插入数据的 ID /获得当前的脚本网址 /把全角数字转为半角数字 /PHP开源代码 /去除 HTML标记 “,“,$txt); $txt = preg_replace(“/rn1,/isU“,“ rn“,$txt); return $txt; /开源代码 OSPhP.COm.CN ? /相对路径转化成绝对路径 /取得所有链接 “ +)“|?s*(+)/i,$code,$arr); /oSPHP.COM.C
12、Nreturn array(name=$arr2,url=$arr1); ? /HTML表格的每行转为 CSV格式数组 *?si“,“,$table); $table = str_replace(“,“,$table); $table = str_replace(“,“tr“,$table); /oSPHP.COM.CN/去掉 HTML 标记 $table = preg_replace(“*?si“,“,$table); /去掉空白字符 $table = preg_replace(“(rn)s+“,“,$table); /开源代码OSPHP.COM.Cn $table = str_replac
13、e(“ “,“,$table); $table = str_replace(“ “,“,$table); $table = explode(“,tr“,$table); /PHP开源代码array_pop($table); return $table; ? /将 HTML表格的每行每列转为数组,采集表格数据 *?si“,“,$table); /oSPHP.COM.CN $table = preg_replace(“*?si“,“,$table); $table = preg_replace(“*?si“,“,$table); $table = str_replace(“,“tr“,$table
14、); /OSPHP.com.CN $table = str_replace(“,“td“,$table); /去掉 HTML 标记 $table = preg_replace(“*?si“,“,$table); /PHP开源代码/去掉空白字符 $table = preg_replace(“(rn)s+“,“,$table); $table = str_replace(“ “,“,$table); /OSPHP.com.CN $table = str_replace(“ “,“,$table); $table = explode(tr, $table); array_pop($table); /OSPHP.COM.Cn开源 foreach ($table as $key=$tr) $td = explode(td, $tr); array_pop($td); $td_array = $td; /PHP开源代码 return $td_array; ? /返回字符串中的所有单词 $distinct=true 去除重复 /打印出为本 PHP项目做出贡献的人员的清单