[PHP]經(jīng)常用到的實(shí)用函數(shù)集合第2/2頁(yè)
4、文件格式類(lèi)
復(fù)制內(nèi)容到剪貼板代碼:
$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',
'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' => 'video/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' => 'application/x-rar-compressed',
'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' => 'application/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',
);
5、php生成excel文檔
<?
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
?>
//改動(dòng)相應(yīng)文件頭就可以輸出.doc .xls等文件格式了
6、時(shí)間比較問(wèn)題
舉一個(gè)簡(jiǎn)單例子說(shuō)明:比如一個(gè)論壇對(duì)當(dāng)天發(fā)表的貼子用new圖片標(biāo)記一下。
方法一:
//$db->rows[$i][date]中為數(shù)據(jù)庫(kù)中datetime字段值.
$today=time();
$theDay=date("Y-m-d H:i:s",$today-24*3600);
$newTag=$db->rows[$i][date]>=$theDay?"<img src='../image/newinfor.gif'>":"";
方法二:
$newTag=$db->rows[$i][date]>=date("Y-m-d 00:00:00")?"<img src='../image/newinfor.gif'>":"";
//提取頁(yè)面和瀏覽器提交的變量,作用相當(dāng)于使PHP.INI開(kāi)了全局變量
復(fù)制內(nèi)容到剪貼板代碼:
@extract($_SERVER, EXTR_SKIP);
@extract($_SESSION, EXTR_SKIP);
@extract($_POST, EXTR_SKIP);
@extract($_FILES, EXTR_SKIP);
@extract($_GET, EXTR_SKIP);
@extract($_ENV, EXTR_SKIP);
//得到ip地址
$ip=$_SERVER['REMOTE_ADDR'];
$ip1 = getenv('HTTP_X_FORWARDED_FOR');
if (($ip1 != "") && ($ip1 != "unknown")) $ip=$ip1;
//讀取文件函數(shù)
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);
fclose($filenum);
return $file_data;
}
}
//寫(xiě)入文件函數(shù)
復(fù)制內(nèi)容到剪貼板代碼:
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;
}
//頁(yè)面快速轉(zhuǎn)向
復(fù)制內(nèi)容到剪貼板代碼:
function turntopage($url="index.php",$info = "頁(yè)面轉(zhuǎn)向中...",$second=2){
print "<html>n<head>n<title>頁(yè)面轉(zhuǎn)向中....</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: 12px}n";
print "A {COLOR: #000000; TEXT-DECORATION: none}n";
print "-->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="#AA9FFF">n";
print " <tr>n";
print " <td height="30" align="center">頁(yè)面轉(zhuǎn)向提示信息</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">如果你的瀏覽器不支持自動(dòng)跳轉(zhuǎn),請(qǐng)按這里</a></td>n";
print " </tr>n";
print " </tr>n";
print " </table></td>n";
print " </tr>n";
print " <tr>n";
print " <td height="200"> </td>n";
print " </tr>n";
print "</table>n";
print "</body>n</html>";
exit;
相關(guān)文章
PHP curl_setopt()函數(shù)實(shí)例代碼與參數(shù)分析
curl_setopt()函數(shù)將為一個(gè)CURL會(huì)話設(shè)置選項(xiàng)。option參數(shù)是你想要的設(shè)置,value是這個(gè)選項(xiàng)給定的值。2011-06-06PHP中include與require使用方法區(qū)別詳解
這篇文章詳細(xì)介紹了PHP中include與require使用方法的區(qū)別,有需要的朋友可以參考一下2013-10-10php中strstr、strrchr、substr、stristr四個(gè)函數(shù)的區(qū)別總結(jié)
這篇文章主要介紹了php中strstr、strrchr、substr、stristr四個(gè)函數(shù)的區(qū)別總結(jié),這4個(gè)函數(shù)是PHP中常用的字符串相關(guān)函數(shù),需要的朋友可以參考下2014-09-09利用php實(shí)現(xiàn)禁用IE和火狐的緩存問(wèn)題
利用php實(shí)現(xiàn)禁用IE和火狐的緩存問(wèn)題,在網(wǎng)速找了好多方法,最終還是解決了,需要了解的朋友可以參考下2012-12-12PHP中常見(jiàn)原生類(lèi)的使用總結(jié)
PHP原生類(lèi)是指在PHP編程語(yǔ)言中自帶的類(lèi)庫(kù),提供了豐富的功能和方法,可以直接使用,不需要額外安裝或引入其他第三方類(lèi)庫(kù),下面我們就來(lái)學(xué)習(xí)一下PHP中常見(jiàn)原生類(lèi)的使用吧2023-11-11簡(jiǎn)單談?wù)凱HP中的include、include_once、require以及require_once語(yǔ)句
include() 、require()語(yǔ)句包含并運(yùn)行指定文件。這兩結(jié)構(gòu)在包含文件上完全一樣,唯一的區(qū)別是對(duì)于錯(cuò)誤的處理。require()語(yǔ)句在遇到包含文件不存在,或是出錯(cuò)的時(shí)候,就停止即行,并報(bào)錯(cuò)。include()則繼續(xù)即行。2016-04-04mysql_fetch_row,mysql_fetch_array,mysql_fetch_assoc的區(qū)別
一直以來(lái),有很多初學(xué)者搞不懂這些Mysql中從查詢結(jié)果集中取得數(shù)據(jù)的函數(shù)之間有什么區(qū)別,今天我就來(lái)秀一把,在秀之前先給大家一段PHP實(shí)例2009-04-04