一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

PHP 中的一些經驗積累

作者:snowai 

最近剛剛完成手中的項目,比較閑。來這兒轉轉,把積累的一些技巧分享給大家!
1、關于php重定向
方法一:header("Location: index.php");
方法二:echo "<script>window.location =/"$php_SELF/";</script>";
方法三:echo "<META HTTP-EQUIV=/"Refresh/" CONTENT=/"0; URL=index.php/">";

2、獲取訪問者瀏覽器

php>function browse_infor()
{
$browser=";$browserver=";
$Browsers =array("Lynx","MOSAIC","AOL","Opera","Java","MacWeb","WebExplorer","OmniWeb");
$Agent = $GLOBALS["HTTP_USER_AGENT"];
for ($i=0; $i<=7; $i++)
{
if (strpos($Agent,$Browsers[$i]))
{
$browser = $Browsers[$i];
$browserver =";
}
}
if (ereg("Mozilla",$Agent) && !ereg("MSIE",$Agent))
{
$temp =explode("(", $Agent); $Part=$temp[0];
$temp =explode("/", $Part); $browserver=$temp[1];
$temp =explode(" ",$browserver); $browserver=$temp[0];
$browserver =preg_replace("/([/d/.]+)/","/1",$browserver);
$browserver = " $browserver";
$browser = "NETscape Navigator";
}
if (ereg("Mozilla",$Agent) && ereg("Opera",$Agent))
{
$temp =explode("(", $Agent); $Part=$temp[1];
$temp =explode(")", $Part); $browserver=$temp[1];
$temp =explode(" ",$browserver);$browserver=$temp[2];
$browserver =preg_replace("/([/d/.]+)/","/1",$browserver);
$browserver = " $browserver";
$browser = "Opera";
}
if (ereg("Mozilla",$Agent) && ereg("MSIE",$Agent))
{
$temp = explode("(", $Agent); $Part=$temp[1];
$temp = explode(";",$Part); $Part=$temp[1];
$temp = explode(" ",$Part);$browserver=$temp[2];
$browserver =preg_replace("/([/d/.]+)/","/1",$browserver);
$browserver = " $browserver";
$browser = "InterNET Explorer";
}
if ($browser!=")
{
$browseinfo = "$browser$browserver";
}
else
{
$browseinfo = "Unknown";
}
return $browseinfo;
}
//調用方法$browser=browseinfo() ;直接返回結果



3、獲取訪問者操作系統

php>function osinfo() {
$os=";
$Agent = $GLOBALS["HTTP_USER_AGENT"];
if (eregi('win',$Agent) && strpos($Agent, '95')) {
$os="Windows 95";
}
elseif (eregi('win 9x',$Agent) && 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('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 OS/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 (ereg('IRIX',$Agent)) {
$os="IRIX";
}
elseif (eregi('FreeBSD',$Agent)) {
$os="FreeBSD";
}
if ($os=='') $os = "Unknown";
return $os;
}
//調用方法$os=os_infor() ;



4、文件格式類

php>$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-Javascript',
'pdf' => 'application/pdf',
'ps' => 'application/postscript',
'eps' => 'application/postscript',
'ai' => 'application/postscript',
'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文檔

php>
<?
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
echo "test1/t";
echo "test2/t/n";
echo "test1/t";
echo "test2/t/n";
echo "test1/t";
echo "test2/t/n";
echo "test1/t";
echo "test2/t/n";
echo "test1/t";
echo "test2/t/n";
echo "test1/t";
echo "test2/t/n";
?>
//改動相應文件頭就可以輸出.doc .xls等文件格式了


6、時間比較問題
舉一個簡單例子說明:比如一個論壇對當天發表的貼子用new圖片標記一下。
方法一:
//$db->rows[$i][date]中為數據庫中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'>":";
7、php中對數據庫操作的封裝
我的例子.........見本文附件!


相關附件:php中對數據庫操作的封裝的例子

php技術PHP 中的一些經驗積累,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 精彩国产熟睡乱子伦午夜片 | 韩国一级毛片视频 | 国产精品成人观看视频免费 | 欧美一区二区三区婷婷月色 | 一本色道久久鬼综合88 | 国产一区二区在线视频播放 | 国产精品第 | 丁香视频在线观看播放 | 国产自在线 | 久久精品伦理 | 久久夜色精品国产亚洲噜噜 | 精品久久久久久综合日本 | 福利一区二区视频 | 巨大巨粗巨长 黑人长吊视频 | 青青草国产精品久久久久 | 二区在线视频 | 国产精品青草久久福利不卡 | 国产精品久久久香蕉 | 色综合社区 | 欧美色综合高清视频在线 | 国内小情侣一二三区在线视频 | 五月丁香花 | 丁香六月 久久久 | 国产成人精品视频2021 | 日韩中文字幕精品 | 久久久久久久综合 | 麻豆国产一区 | 美女视频一区二区三区在线 | 国产有码视频 | 色哟哟哟在线观看www | 中文字幕一区二区三区永久 | 色天天网 | 八月丁香婷婷 | 精品成人一区二区 | 中文字幕一区视频 | 国产中文视频 | 免费自拍视频 | 99久女女精品视频在线观看 | 欧美日本视频在线观看 | 91网站免费在线观看 | 国产成人午夜91精品麻豆剧场 |