经验积累,献给PHP爱好者!!!_PHP
最近刚刚完成手中的项目,比较闲。来这儿转转,把积累的一些技巧分享给大家!
1、关于PHP重定向
方法一:header("Location: index.php");
方法二:echo "<script>window.location =\"$PHP_SELF\";</script>";
方法三:echo "";
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{
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、获取访问者操作系统
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、文件格式类
$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文档
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?"":"";
方法二:
$newTag=$db->rows[$i][date]>=date("Y-m-d 00:00:00")?"":"";
7、PHP中对数据库操作的封装
我的例子.........见上面附件!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

「金凡離職」,估計是所有米粉近期最關心的事情,有人因此奔走相告,嘀咕著:“小米系統有救了”,有人則是笑著嘲諷:“換誰來都一樣”。更有意思的地方在於,「金凡離職」的消息並非出自小米官方或是其他內部人士,而是因為有網友發現金凡的微博已經清空了所有內容,看起來就像是跑路後為了避嫌,清空社群帳號一樣。圖源:微博這則消息很快就引起了大量數碼博主和媒體的關注,其中甚至包括鳳凰網這樣的權威媒體,一時之間成為數碼圈最新最熱的“瓜”。雖然後續小米公關部的負責人王化出來闢謠,表示金凡並沒有離職,而是正在“閉關”,為

近期,復旦大學自然語言處理團隊(FudanNLP)推出LLM-basedAgents綜述論文,全文長達86頁,共有600多篇參考文獻!作者們從AIAgent的歷史出發,全面梳理了基於大型語言模型的智慧代理現狀,包括:LLM-basedAgent的背景、組成、應用場景、以及備受關注的代理社會。同時,作者們探討了Agent相關的前瞻開放問題,對於相關領域的未來發展趨勢具有重要價值。論文連結:https://arxiv.org/pdf/2309.07864.pdfLLM-basedAgent論文列表:

在當前網路高速發展的時代,PHP作為一種伺服器端腳本語言,被越來越多的開發者所採用。 PHP具有簡單易學、靈活、開源免費等優勢,可快速開發各種網站和Web應用。然而,身為PHP開發者,要想在激烈的競爭中脫穎而出並寫出高效穩定的程式碼,還需要掌握各種功能的實現技巧和經驗。首先,合理規劃專案架構是開發PHP應用的關鍵。一個良好的專案架構可以提供更好的程式碼可維

常用的函數和方法在Python中,os庫提供了大量與作業系統相關的函數和方法。以下是一些常用的函數和方法及其詳細介紹、案例和完整註釋:getcwd()函數:取得目前工作目錄。 importos#取得目前工作目錄current_dir=os.getcwd()print(current_dir)在上面的程式碼中,我們使用getcwd()函數取得了目前的工作目錄,並將其指派給變數current_dir。該函數傳回一個字串,表示目前工作目錄的路徑。 listdir()函數:列出指定目錄下的所有檔案和子目錄i

os有多種意義:1、作業系統(operation system),管理電腦硬體與軟體資源的程式;2、原始碼開放(Open Source);3、開放式系統(Opening System);4、操作員站( Operator Station)。

踩過的坑:Go語言專案開發經驗與教訓在軟體開發的道路上,每個開發者都會不可避免地踩過一些坑。當然,對於Go語言的開發者來說也不例外。本文將分享我在使用Go語言進行專案開發過程中所踩過的坑,希望能為其他開發者帶來一些經驗和教訓。不同版本的Go語言在使用Go語言進行專案開發時,我們必須專注於Go語言的版本。不同版本之間可能存在一些語言上的差異或API的變動,這些

深入理解JavaGUI開發的經驗與建議作為一種常用的物件導向程式語言,Java在軟體開發中扮演著舉足輕重的角色。而在Java開發中,GUI(GraphicalUserInterface)即圖形使用者介面的開發更是日常工作中所需掌握的重要技能之一。在GUI開發中,豐富的使用者介面和互動效能會直接影響軟體的使用者體驗和使用者滿意度,因此,深入理解

在使用Go語言(golang)進行開發時,可能會遇到「undefined:os.MkdirAll」錯誤。這個錯誤是由於程式碼中呼叫了os套件中的MkdirAll()函數但是卻找不到函數的定義,即MkdirAll()函數沒有被正確地導入所致。在這篇文章中,我們將解釋這個錯誤的原因以及如何解決它。理解「undefined:os.Mkdir
