Summary of php code writing habits Optimization

(1) The static method is four times faster than the normal method.(2) echo output is faster than print(3) Use the connection character instead.(4) take the maximum value before the loop, instead of taking the value in the loop.Correct Method$ Max =

Thinkphp multi-Table transaction details

As follows:Copy codeThe Code is as follows:Function makeAcquire ($ nUsers, $ nAwards){// Update the database$ TranDb = new Model ();$ TranDb-> startTrans ();For ($ I = 0; $ I {// Update the Acquire table$ FlagAc = $ tranDb-> table ('acquire ')-> add

Empty function-based output details

$ A = '';Echo '1. --------------- '. empty ($ a).' ';$ A = '0 ';Echo '2. --------------- '. empty ($ a).' ';$ A = 0;Echo '3. --------------- '. empty ($ a).' ';$ A = null;Echo '4. --------------- '. empty ($ a).' ';$ A = 'null ';Echo '5. --------

PHP retrieves the start date and end date of the Week (month) of the current date (implementation code)

CodeCopy codeThe Code is as follows:// Obtain the start time and end time of the week of the specified date.Function getWeekRange ($ date ){$ Ret = array ();$ Timestamp = strtotime ($ date );$ W = strftime ('% U', $ timestamp );$ Ret ['sdate'] =

Php character filtering class, used to filter data input by various users

The Code is as follows:Copy codeThe Code is as follows:Abstract class Filter {// filter parent classPrivate $ blackstr = array ();Private $ whitestr = array ();Function filtit ($ str ){// Do something}}Class LoginFilter extends Filter {// for user

Php form verification implementation code

Copy codeThe Code is as follows: Form name: password: Password confirmation: Gender: male female birthday: Email: occupation: Copy codeThe Code is as follows:Function form_sub (){If (! Test_username (document.

Php mssql time format

Of course, it is more flexible to solve in the program, for example:"Select convert (char, Date Field, 120) as date2 from table"Convert (char, date, N)N date style0 04 2 2005 AM1 04/02/052 05.04.023 02/04/054 02.04.055 02-04-056 02 04 057 04 02, 0509

PHP programs that prevent MySQL injection or HTML form abuse

The intention of MySQL injection is to take over the website database and steal information. Common open-source databases, such as MySQL, have been used by many website developers to store important information, such as passwords, personal

Factory model of php design model

I often use mysql databases, so the program only writes mysql database operations. I hope you can write all the other classes in your hand. You 'd better send me one.Db_mysql.php inherits the db. php interface and implements various database

Php searches for another string in the string

back to list "Method =" post ">In "> Search for "> > The second string can be anywhere in the first string > The first string starts with the second string > The first string ends with the second string > Case Sensitive If (isset ($ string) and

Function Code for PHP integration with FCK

Copy codeThe Code is as follows:// Define a function to call FCKeditorFunction call_fck ($ input_name, $ input_value, $ w = '000000', $ h = '000000 '){Include_once 'fckeditor/fckeditor. php ';$ Fcked = new FCKeditor ($ input_name );$ Fcked->

Php determines the Inclusion Method attributes of characters and strings

The following describes how to use it:1. strstr: returns a string from the start to the end of the character to be judged. If no return value exists, it does not containCopy codeThe Code is as follows:/* Example in the manual */$ Email = 'user @

PHP generic pagination page. php [google pagination]

Page. phpCopy codeThe Code is as follows:/**** Generic php paging class. (Like Google style)** You only need to provide two parameters: the total number of records and the number of records displayed on each page. (Detailed instructions are provided

Php code for generating random numbers or strings

$ Len indicates the length. The Code is as follows:Copy codeThe Code is as follows:/*** Generate random strings** Generates a random string of the specified length and returns it to the user.** @ Access public* @ Param int $ len: number of digits of

Pagination code for php automatic adaptation range

Copy codeThe Code is as follows:Function page ($ page, $ total, $ phpfile, $ pagesize = 10, $ pagelen = 7 ){$ Pagecode = ''; // defines variables and stores HTML generated by page.$ Page = intval ($ page); // avoid non-numeric page numbers$ Total =

Php checks whether the string is UTF-8 encoded.

Function is_utf8 ($ string ){Return preg_match ('% ^ (? :[\ X09 \ x0A \ x0D \ x20-\ x7E] # ASCII| [\ XC2-\ xDF] [\ x80-\ xBF] # non-overlong 2-byte| \ XE0 [\ xA0-\ xBF] [\ x80-\ xBF] # excluding overlongs| [\ XE1-\ xEC \ xEE \ xEF] [\ x80-\ xBF] {2}

Passing parameter instance code between PHP pages

 First, we will introduce how to query data by passing values in a form.Task target: Enter the Department name in the form to query the personnel information of the corresponding department.Create a search. php file first.Step 1: Insert a form that

PHP advanced mysql courseware page 1/2

Responsibilities of the database administratorServer startup and ShutdownUser account maintenanceLog File MaintenanceDatabase backup and copyServer OptimizationSoftware updates for the database management systemSecurity of Data DirectoriesServer

Several Methods for php to read database information

$ Dbh = @ mysql_connect ("localhost: 3306", "root", "9999 ");/* Define the variable dbh. The mysql_connect () function means to connect to the mysql database, and "@" means to block the error */If (! $ Dbh) {die ("error ");}/* The die () function

How to solve the Cannot modify header information problem in php

Obviously, this is because of setcookie. I checked the Internet and explained the following: the cookie itself has some restrictions, for example:1. The description of the call to setcookie must be placed before the tag2. You cannot use echo before

Total Pages: 12780 1 .... 12323 12324 12325 12326 12327 .... 12780 Go to: GO

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.