Some experience in PHP _ PHP Tutorial

Source: Internet
Author: User
Some experience in PHP. Recently, projects in the hands are relatively idle. Come here and share some accumulated skills with you! 1. PHP redirection Method 1: header (Location: index. php); Method 2: recently completed projects in the hands, relatively idle. Come here and share some accumulated skills with you! 1. PHP redirection Method 1: header ("Location: index. php"); Method 2: echo ""; Method 3: echo" "; 2. obtain the visitor's browser 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 = e Xplode (")", $ 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]; $ bro Wserver = preg_replace ("/([d.] +)/"," 1 ", $ browserver); $ browserver =" $ browserver "; $ browser =" Internet Explorer ";} if ($ browser! = "") {$ Browseinfo = "$ browser $ browserver";} else {$ browseinfo = "Unknown";} return $ browseinfo ;} // call method $ browser = browseinfo (); directly return result 3. obtain the visitor's OS 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;} // call method $ OS = OS _infor (); 4. file format class $ 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 generates excel documents // You can change the response file header to export the file formats such as .doc. xls. 6. time comparison. for example, a forum can mark the post posted on the current day with a new image. Method 1: // $ db-> rows [$ I] [date] indicates the datetime field value in the database. $ today = time (); $ theDay = date ("Y-m-d H: I: s", $ today-24*3600 ); $ newTag = $ db-> rows [$ I] [date]> = $ theDay? "": ""; Method 2: $ newTag = $ db-> rows [$ I] [date]> = date ("Y-m-d 00:00:00 ")? "": ""; 7. Examples of database operations encapsulated in PHP ...... see the attachment in this article!

Bytes. Come here and share some accumulated skills with you! 1. PHP redirection Method 1: header (Location: index. php); Method 2...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.