知识大全 PHP常用函数
Posted 知
篇首语:情况是在不断地变化,要使自己的思想适应新的情况,就得学习。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 PHP常用函数相关的知识,希望对你有一定的参考价值。
PHP常用函数 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
<?php function DateAdd($date $int $unit = "d") //时间的增加(还可以改进成时分秒都可以增加 有时间再补上) $dateArr = explode(" " $date); $value[$unit] = $int; //OSPHP CN return date("Y m d" mktime( $dateArr[ ] + $value[ m ] $dateArr[ ] + $value[ d ] $dateArr[ ] + $value[ y ])); //OSPHP CN function GetWeekDay($date) //计算出给出的日期是星期几 $dateArr = explode(" " $date); return date("w" mktime( $dateArr[ ] $dateArr[ ] $dateArr[ ])); ?> <? function GetIP() //获取IP if ($_SERVER["HTTP_X_FORWARDED_FOR"]) $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else if ($_SERVER["HTTP_CLIENT_IP"]) $ip = $_SERVER["HTTP_CLIENT_IP"]; else if ($_SERVER["REMOTE_ADDR"]) $ip = $_SERVER["REMOTE_ADDR"]; 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; ?><? function check_date($date) //检查日期是否合法日期 $dateArr = explode(" " $date); if (is_numeric($dateArr[ ]) && is_numeric($dateArr[ ]) && is_numeric($dateArr[ ])) checkdate($dateArr[ ] $dateArr[ ] $dateArr[ ]); return false; function check_time($time) //检查时间是否合法时间 //开源OSPhP CN $timeArr = explode(":" $time); if (is_numeric($timeArr[ ]) && is_numeric($timeArr[ ]) && is_numeric($timeArr[ ])) $timeArr[ ] >= && $timeArr[ ] <= ) && ($timeArr[ ] >= && $timeArr[ ] <= ) && ($timeArr[ ] >= && $timeArr[ ] <= )) //开源OSPhP CN return true; else return false; return false; function DateDiff($date $date $unit = "") //时间比较函数 返回两个日期相差几秒 几分钟 几小时或几天 //开源代码OSPhP CN switch ($unit) case s : $dividend = ; break; case i : $dividend = ; break; case h : $dividend = ; break; case d : $dividend = ; break; //oSPHP CN default: $dividend = ; $time = strtotime($date ); $time = strtotime($date ); if ($time && $time ) $time $time ) / $dividend; return false; ?> PHP重定向 <? 方法一 header("Location: index php"); 方法二 echo "<scrīpt>window location ="$PHP_SELF";</scrīpt>"; //PHP开源代码 方法三 echo "<META HTTP EQUIV="Refresh" CONTENT=" ; URL=index php">"; ?> 获取访问者浏览器 <? function browse_infor() $browser="";$browserver=""; $Browsers =array("Lynx" "MOSAIC" "AOL" "Opera" "JAVA" "MacWeb" "WebExplorer" "OmniWeb"); $Agent = $GLOBALS["HTTP_USER_AGENT"]; for ($i= ; $i<= ; $i++) //OsPHP CN if (strpos($Agent $Browsers[$i])) $browser = $Browsers[$i]; $browserver =""; if (ereg("Mozilla" $Agent) && !ereg("MSIE" $Agent)) $temp =explode("(" $Agent); $Part=$temp[ ]; $temp =explode("/" $Part); $browserver=$temp[ ]; $temp =explode(" " $browserver); $browserver=$temp[ ]; $browserver =preg_replace("/([d ]+)/" " " $browserver); $browserver = " $browserver"; //OSPHP Cn开源 $browser = "Netscape Navigator"; if (ereg("Mozilla" $Agent) && ereg("Opera" $Agent)) $temp =explode("(" $Agent); $Part=$temp[ ]; $temp =explode(")" $Part); $browserver=$temp[ ]; $temp =explode(" " $browserver);$browserver=$temp[ ]; $browserver =preg_replace("/([d ]+)/" " " $browserver); $browserver = " $browserver"; $browser = "Opera"; if (ereg("Mozilla" $Agent) && ereg("MSIE" $Agent)) //OSPHP CN $temp = explode("(" $Agent); $Part=$temp[ ]; $temp = explode(";" $Part); $Part=$temp[ ]; $temp = explode(" " $Part);$browserver=$temp[ ]; $browserver =preg_replace("/([d ]+)/" " " $browserver); $browserver = " $browserver"; $browser = "Internet Explorer"; if ($browser!="") $browseinfo = "$browser$browserver"; else $browseinfo = "Unknown"; return $browseinfo; //调用方法$browser=browseinfo() ;直接返回结果 ?> //oSPHP 获取访问者操作系统 <? function osinfo() $os=""; $Agent = $GLOBALS["HTTP_USER_AGENT"]; if (eregi( win $Agent) && strpos($Agent )) //PHP开源代码 $os="Windows "; elseif (eregi( win x $Agent) && strpos($Agent )) $os="Windows ME"; elseif (eregi( win $Agent) && ereg( $Agent)) //OSPHP CN $os="Windows "; elseif (eregi( win $Agent) && eregi( nt $Agent)) $os="Windows "; elseif (eregi( win $Agent) && eregi( nt $Agent)) //开源代码OSPHP Cn $os="Windows NT"; elseif (eregi( win $Agent) && eregi( nt $Agent)) $os="Windows XP"; elseif (eregi( win $Agent) && ereg( $Agent)) $os="Windows "; elseif (eregi( linux $Agent)) $os="Linux"; elseif (eregi( unix $Agent)) $os="Unix"; eregi( sun $Agent) && eregi( os $Agent)) $os="SunOS"; elseif (eregi( ibm $Agent) && eregi( os $Agent)) $os="IBM OS/ "; 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"; //PHP开源代码 elseif (eregi( NetBSD $Agent)) $os="NetBSD"; elseif (eregi( BSD $Agent)) $os="BSD"; elseif (ereg( OSF $Agent)) $os="OSF "; elseif (ereg( IRIX $Agent)) $os="IRIX"; elseif (eregi( FreeBSD $Agent)) $os="FreeBSD"; $os== ) $os = "Unknown"; return $os; //调用方法$os=os_infor() ; ?> 文件格式类 <? $mime_types = array( gif => image/gif 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 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 javascrīpt pdf => application/pdf ps => application/postscrīpt eps => application/postscrīpt ai => application/postscrīpt wmf => application/x msmetafile css => text/css => text/ => text/ txt => text/plain xml => text/xml wml => text/wml wbmp => image/vnd wap wbmp mid => audio/midi wav => audio/wav mp => audio/mpeg mp => audio/mpeg avi => video/x msvideo mpeg => video/mpeg mpg => video/mpeg qt => video/quicktime mov => video/quicktime //开源代码OSPHP Cn lha => application/x lha lzh => application/x lha z => application/x press gtar => application/x gtar gz => application/x gzip gzip => application/x gzip tgz => application/x gzip tar => application/x tar bz => application/bzip zip => application/zip arj => application/x arj rar => application/x rar pressed hqx => application/mac binhex sit => application/x stuffit bin => application/x macbinary uu => text/x uuencode uue => text/x uuencode latex => application/x latex //PHP开源代码 ltx => application/x latex tcl => application/x tcl pgp => application/pgp asc => application/pgp exe => application/x msdownload doc => application/msword //OSPHP CN rtf => application/rtf xls => application/vnd ms excel ppt => application/vnd ms powerpoint mdb => application/x msaccess wri => application/x mswrite ); ?>
else if (
return
if ((
return (float)( elseif ( if (
生成excel文档 <? header("Content type:application/vnd ms excel"); header("Content Disposition:filename=test xls"); echo "test t"; echo "test tn"; echo "test t"; echo "test tn"; echo "test t"; "test tn"; echo "test t"; echo "test tn"; echo "test t"; echo "test tn"; echo "test t"; echo "test tn"; //改动相应文件头就可以输出 doc xls等文件格式了 ?> 时间比较问题 举一个简单例子说明:比如一个论坛对当天发表的贴子用new图片标记一下方法一 <? //$db >rows[$i][date]中为数据库中datetime字段值 $today=time(); $theDay=date("Y m d H:i:s" $today * ); $newTag=$db >rows[$i][date]>=$theDay?"<img src= /image/newinfor gif >":"";
//方法二 $newTag=$db >rows[$i][date]>=date("Y m d : : ")?"<img src= /image/newinfor gif >":""; ?> //提取页面和浏览器提交的变量 作用相当于使PHP INI开了全局变量
<? @extract($_SERVER EXTR_SKIP); @extract($_SESSION EXTR_SKIP); @extract($_POST EXTR_SKIP); @extract($_FILES EXTR_SKIP); //OSPHP CN @extract($_GET EXTR_SKIP); @extract($_ENV EXTR_SKIP); ?> //写入文件函数 <? 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; ?> //页面快速转向 <? function turntopage($url="index php" $info = "页面转向中 " $second= ) print "<>n<head>n<title>页面转向中 </title>n"; print "<meta equiv="refresh" content="$second;url=$url">n";
print "<style type="text/css">n<! n"; print "td font family: "Verdana" "Arial";font size: pxn"; print "A COLOR: # ; TEXT DECORATION: nonen"; print " >n</style>n"; print "</head>n<body>n"; print "<table border=" " align="center">n"; //PHP开源代码 print " <tr>n"; print " <td > </td>n"; print " </tr>n"; print " <tr>n"; print " <td align="center">n"; print " <table border=" " cellpadding=" " bgcolor="#AA FFF">n";
//PHP开源代码
print " <tr>n"; print " <td align="center">页面转向提示信息</td>n"; print " </tr>n"; print " <tr>n"; print " <td align="center">$info</td>n"; print " </tr>n"; print " <tr>n"; //开源OSPhP CN print " <td align="center">n"; print " <a href="$url">如果你的浏览器不支持自动跳转 请按这里</a></td>n"; print " </tr>n"; print " </tr>n"; print " </table></td>n"; print " </tr>n"; print " <tr>n";print " <td > </td>n"; print " </tr>n"; print "</table>n"; print "</body>n</>"; exit; ?> echo cha138/Article/program/PHP/201311/20995
相关参考
PHP最常用的ini函数 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 针对PHP配置文件PHP
DOM函数 aDOMDocument>load() 作用加载xml文件 用法DOMDocument>load(stringfilename) 参数filenamexml文件;
DOM函数 aDOMDocument>load() 作用加载xml文件 用法DOMDocument>load(stringfilename) 参数filenamexml文件;
知识大全 基于php常用函数总结(数组,字符串,时间,文件操作)
数组:【重点】implode(分隔arr)把数组值数据按指定字符连接起来例如$arr=array();$str=implode($arr);explode([分隔]arr)按指定规则对一个字符串进
php函数method_exists()与is_callable()的区别在哪?在php面相对象设计过程中往往我们需要在调用某一个方法是否属于某一个类的时候做出判断常用的方法有method_exist
php技巧:几个比较实用的PHP函数 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! sys_ge
PHP5函数小全 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 很多PHP前辈都写了PHP大全但
解析PHP函数array 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 我们都知道PHP中的数组
本篇文章是对计算php页面运行时间的函数进行了详细的分析介绍需要的朋友参考下 一个计算php页面运行时间的函数复制代码代码如下:cha138/Article/program/P
•strtotime函数的一些用法•strtotime函数的实现基本原理•strtotime(”month”)求值失败的原因strtotime函数的一些用法strtotime(”JAN”)和str