PHP中的一些经验积累
时间:2007-02-17 来源:PHP爱好者
最近刚刚完成手中的项目,比较闲。来这儿转转,把积累的一些技巧分享给大家!
1、关于PHP重定向
方法一:header("Location: index.php");
方法二:echo "<script>window.location ="$PHP_SELF";</script>";
方法三:echo "<META HTTP-EQUIV="Refresh" CONTENT="0; URL=index.php">";
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
2、获取访问者浏览器
function browse_infor()
{
$browser="";$browserver="";
$Browsers =array("Lynx","MOSAIC","AOL","Opera","JAVA","MacWeb","WebExplorer","OmniWeb");
$Agent = $GLOBALS["HTTP_USER_AGENT"];
for ($i=0; $i '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',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'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',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'css' => 'text/css',
'htm' => 'text/html',
'html' => 'text/html',
'txt' => 'text/plain',
'xml' => 'text/xml',
'wml' => 'text/wml',
'wbmp' => 'image/vnd.wap.wbmp',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'mid' => 'audio/midi',
'wav' => 'audio/wav',
'mp3' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'avi' => 'video/x-msvideo',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'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',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'hqx' => 'application/mac-binhex40',
'sit' => 'application/x-stuffit',
'bin' => 'application/x-macbinary',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'uu' => 'text/x-uuencode',
'uue' => 'text/x-uuencode',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'latex'=> 'application/x-latex',
'ltx' => 'application/x-latex',
'tcl' => 'application/x-tcl',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'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',
); ww w.china it power.coeS14YRLY72mlDqP0EfZtofcsh
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";
?>
//改动相应文件头就可以输出.doc .xls等文件格式了 ww w.china it power.coeS14YRLY72mlDqP0EfZtofcsh
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='../images_php/2005-8/200582212550481.gif'>":"";
方法二:
$newTag=$db->rows[$i][date]>=date("Y-m-d 00:00:00")?"<img src='../images_php/2005-8/200582212550481.gif'>":"";
7、PHP中对数据库操作的封装
我的例子.........见本文附件! ww w.china it power.coeS14YRLY72mlDqP0EfZtofcsh
相关附件:PHP中对数据库操作的封装的例子
ww w.china it power.coeS14YRLY72mlDqP0EfZtofcsh
php爱好者站 http://www.phpfans.net dreamweaver|flash|fireworks|photoshop.
1、关于PHP重定向
方法一:header("Location: index.php");
方法二:echo "<script>window.location ="$PHP_SELF";</script>";
方法三:echo "<META HTTP-EQUIV="Refresh" CONTENT="0; URL=index.php">";
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
2、获取访问者浏览器
function browse_infor()
{
$browser="";$browserver="";
$Browsers =array("Lynx","MOSAIC","AOL","Opera","JAVA","MacWeb","WebExplorer","OmniWeb");
$Agent = $GLOBALS["HTTP_USER_AGENT"];
for ($i=0; $i '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',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'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',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'css' => 'text/css',
'htm' => 'text/html',
'html' => 'text/html',
'txt' => 'text/plain',
'xml' => 'text/xml',
'wml' => 'text/wml',
'wbmp' => 'image/vnd.wap.wbmp',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'mid' => 'audio/midi',
'wav' => 'audio/wav',
'mp3' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'avi' => 'video/x-msvideo',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'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',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'hqx' => 'application/mac-binhex40',
'sit' => 'application/x-stuffit',
'bin' => 'application/x-macbinary',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'uu' => 'text/x-uuencode',
'uue' => 'text/x-uuencode',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'latex'=> 'application/x-latex',
'ltx' => 'application/x-latex',
'tcl' => 'application/x-tcl',
中国IT动力eS14YRLY72mlDqP0EfZtofcsh
'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',
); ww w.china it power.coeS14YRLY72mlDqP0EfZtofcsh
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";
?>
//改动相应文件头就可以输出.doc .xls等文件格式了 ww w.china it power.coeS14YRLY72mlDqP0EfZtofcsh
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='../images_php/2005-8/200582212550481.gif'>":"";
方法二:
$newTag=$db->rows[$i][date]>=date("Y-m-d 00:00:00")?"<img src='../images_php/2005-8/200582212550481.gif'>":"";
7、PHP中对数据库操作的封装
我的例子.........见本文附件! ww w.china it power.coeS14YRLY72mlDqP0EfZtofcsh
相关附件:PHP中对数据库操作的封装的例子
ww w.china it power.coeS14YRLY72mlDqP0EfZtofcsh
php爱好者站 http://www.phpfans.net dreamweaver|flash|fireworks|photoshop.
相关阅读 更多 +