Home Backend Development PHP Tutorial PHP中的一些经验积累_PHP

PHP中的一些经验积累_PHP

Jun 01, 2016 pm 12:38 PM
agent os experience

最近刚刚完成手中的项目,比较闲。来这儿转转,把积累的一些技巧分享给大家!
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?"PHP中的一些经验积累_PHP":"";
方法二:
$newTag=$db->rows[$i][date]>=date("Y-m-d 00:00:00")?"PHP中的一些经验积累_PHP":"";

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Mi fans criticize, Xiaomi stays, The Paper OS can't live without Jin Fan? Mi fans criticize, Xiaomi stays, The Paper OS can't live without Jin Fan? Aug 07, 2024 pm 06:16 PM

"Jin Fan's resignation" is probably what all rice fans are most concerned about recently. Some people rushed to tell each other, muttering: "Xiaomi system can be saved", while others laughed and mocked: "No matter who replaces him, it will be the same." What’s more interesting is that the news of “Jin Fan’s resignation” did not come from Xiaomi officials or other insiders, but because some netizens discovered that Jin Fan’s Weibo had been cleared of all content. It looked like he was running away to avoid suspicion. , the same as clearing social accounts. Source: Weibo This news quickly attracted the attention of a large number of digital bloggers and media, including even authoritative media such as Phoenix.com, and it suddenly became the latest and hottest "melon" in the digital circle. Although Wang Hua, the head of Xiaomi's public relations department, later refuted the rumors, saying that Jin Fan had not resigned, but was "retreating" to work for

Fudan NLP team released an 80-page overview of large-scale model agents, providing an overview of the current situation and future of AI agents in one article Fudan NLP team released an 80-page overview of large-scale model agents, providing an overview of the current situation and future of AI agents in one article Sep 23, 2023 am 09:01 AM

Recently, the Fudan University Natural Language Processing Team (FudanNLP) launched a review paper on LLM-basedAgents. The full text is 86 pages long and has more than 600 references! Starting from the history of AIAgent, the authors comprehensively sort out the current status of intelligent agents based on large-scale language models, including: the background, composition, application scenarios of LLM-basedAgent, and the agent society that has attracted much attention. At the same time, the authors discussed forward-looking and open issues related to Agent, which are of great value to the future development trends of related fields. Paper link: https://arxiv.org/pdf/2309.07864.pdfLLM-basedAgent paper list:

PHP development experience sharing: experience and suggestions for mastering the implementation of various functions PHP development experience sharing: experience and suggestions for mastering the implementation of various functions Nov 22, 2023 pm 12:02 PM

In the current era of rapid development of the Internet, PHP, as a server-side scripting language, is adopted by more and more developers. PHP has the advantages of being easy to learn, flexible, open source and free, and can quickly develop various websites and web applications. However, as a PHP developer, if you want to stand out in the fierce competition and write efficient and stable code, you also need to master the implementation skills and experience of various functions. First of all, reasonable planning of project architecture is the key to developing PHP applications. A good project structure can provide better code maintainability

What are the commonly used methods in python os library? What are the commonly used methods in python os library? May 03, 2023 am 09:55 AM

Commonly used functions and methods In Python, the os library provides a large number of operating system-related functions and methods. The following are some commonly used functions and methods and their detailed introduction, cases and complete comments: getcwd() function: Get the current working directory. importos#Get the current working directory current_dir=os.getcwd() print(current_dir) In the above code, we use the getcwd() function to obtain the current working directory and assign it to the variable current_dir. This function returns a string representing the path to the current working directory. listdir() function: List all files and subdirectories in the specified directory i

What does os mean? What does os mean? Mar 25, 2021 pm 04:00 PM

os has many meanings: 1. Operating system (operation system), a program that manages computer hardware and software resources; 2. Open Source; 3. Opening System; 4. Operator station ( Operator Station).

Pitfalls stepped on: Go language project development experience and lessons Pitfalls stepped on: Go language project development experience and lessons Nov 03, 2023 am 08:14 AM

Traps that have been stepped on: Go language project development experience and lessons. On the road of software development, every developer will inevitably step on some pitfalls. Of course, this is no exception for Go language developers. This article will share the pitfalls I have encountered during project development using the Go language, hoping to bring some experience and lessons to other developers. Different versions of Go language When using Go language for project development, we must pay attention to the version of Go language. There may be some language differences or API changes between different versions. These

In-depth understanding of Java GUI development experience and suggestions In-depth understanding of Java GUI development experience and suggestions Nov 22, 2023 am 10:10 AM

In-depth understanding of Java GUI development experience and suggestions As a commonly used object-oriented programming language, Java plays a pivotal role in software development. In Java development, the development of GUI (Graphical User Interface) is one of the important skills that need to be mastered in daily work. In GUI development, rich user interface and interactive performance will directly affect the user experience and user satisfaction of the software. Therefore, in-depth understanding

How to solve 'undefined: os.MkdirAll' error in golang? How to solve 'undefined: os.MkdirAll' error in golang? Jun 25, 2023 pm 06:18 PM

When developing using the Go language (golang), you may encounter the "undefined:os.MkdirAll" error. This error is due to the fact that the MkdirAll() function in the os package is called in the code but the definition of the function cannot be found, that is, the MkdirAll() function is not imported correctly. In this article, we will explain the cause of this error and how to fix it. Understanding "undefined:os.Mkdir

See all articles