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 =

Detailed description of CSV file reading based on PHP

Reads data from all rows in a CSV file at a time. CopyCode The Code is as follows: $ File = fopen('windows_201511s.csv ', 'R '); While ($ DATA = fgetcsv ($ file) {// read the contents of a row in the CSV each time. // Print_r ($ data); // This is

Use php to count the number of Chinese and English characters in a string

Copy codeThe Code is as follows: Echo $ str = "43fdf test fdsfadaf43543543 the employee asked about the anti-leech 5345 gfdgd "; Preg_match_all ("/[0-9] {1}/", $ str, $ arrNum ); Preg_match_all ("/[a-zA-Z] {1}/", $ str, $ arrAl ); Preg_match_all (

Parsing unexpected exceptions during int conversion such as intval () in PHP

Let's take a look at the following online test code: Copy codeThe Code is as follows: $ A = 9.45*100; Var_dump ($ ); Var_dump (intval ($ )); $ A = 945*1.00; Var_dump ($ ); Var_dump (intval ($ )); ?> Running result: float (945) int (944) float (945

Analysis on cross-origin instances of jsonp in php

Now we have such HTML file testjsonp.html under the domain name www.test.com: Copy codeThe Code is as follows: Untitled Page Note: To truly run the above Code, you may need jquery files, you can change to the file path of jquery in your

Parse the differences between array_merge and array + array in php

Array_merge discards the key of the original number, retains the key in the string form, and then forms a new array. no matter whether the key name is the same or not, it is not merged, unless the key name and value are the same and must also be a

PHP stack and queuing Learning

In PHP, arrays are often used as stacks (first-in-first-out: LIFO) and queues (first-in-first-out: FIFO. PHP provides a set of functions for pushing, pop (stack), and shift and unshift (Queue) to operate on array elements. Stacks and queues are

PHP clears the varnish cache (including files on the specified site)

Folder content cannot be cleared. Only the specified link cache can be cleared. Copy codeThe Code is as follows: Function clearVarnish ($ ip, $ url, $ host = null ){ $ Errstr = '';$ Errno = '';$ Varnist_arr = isset ($ host )? $ Host: C ('varnish _

Classic usage of PHP Variable Functions

Copy codeThe Code is as follows: Function map ($ fun, $ list, $ params = array ()){ $ Acc = NULL; $ Last = array_push ($ params, NULL, $ acc)-1; Foreach ($ list as $ params [$ last-1]) {// This method is amazing for the first time. $ Params [$

How to generate thumbnails based on PHP server Images

Copy codeThe Code is as follows: // Define the size of the thumbnail.$ PicSize = array ( '1970 _ 100' => 1, '2017 _ 000000' => 1 ); $ ImagePath = "../image /"; Function parseUrl ($ url ){ Preg_match ("/(? P [\ w \ d] +) _ w (? P \ d +) _ h (? P \

Use PHP to find the relative path of the two files

Copy codeThe Code is as follows: function compare ($ ph1, $ ph2 ){ $ Ret = ''; $ _ F1Arr = explode ("/", $ ph1 ); $ _ F2Arr = explode ("/", $ ph2 ); $ F1 = array_pop ($ _ f1Arr );$ F2 = array_pop ($ _ f2Arr );For ($ I = 0; $ I If ($ _ f1Arr [$ I]! =

Analysis on using Turck-mmcache compilation to accelerate and optimize PHP code

Php_screw is really good, but it can only play the role of encryption, and does not play the role of acceleration and optimization. Let's take a look: Turck MMCacheIt accelerates and optimizes php code by compiling php code. If the released php code

Summary of methods for connecting PHP to the Access Database

PHP code: Note that php uses realpath to obtain the path.Copy codeThe Code is as follows: $ Connstr = "DRIVER = {Microsoft Access Driver (*. mdb)}; DBQ =". realpath ("data. mdb ");$ Connid = odbc_connect ($ connstr, "", "", SQL _CUR_USE_ODBC );$

How to Use php to determine the type of the server operating system

I use winXP for local development, but the uploaded server is linux. I always need to change the configuration file before each upload, and there are other things, Now, by determining the type of the current server to determine what program to

Parsing php uses regular expressions to solve the problem of collecting content Layout

The problem that is often encountered during collection is the problem of content formatting. After some time, I wrote a function that replaces html tags and styles with regular expressions, sharing them. Copy codeThe Code is as follows :/** *

Parse the fopen () function in php and use the description of open file Mode

The fopen () function is used to open a file in PHP.The first parameter of this function contains the name of the file to be opened, and the second parameter specifies the mode used to open the file: Copy codeThe Code is as follows: $ File = fopen (

Three methods to parse PHP to generate static html files

This article describes three methods for generating static html files in Php. 1. The following is a template method! Copy codeThe Code is as follows: $ Fp = fopen ("templets.html", ""); If ($ fp ){ $ Fup = fread ($ fp, filesize ("templets.html "));

PHP source code for mass mailing

Copy codeThe Code is as follows: // Request the PHPmailer class file Require_once ("class. phpmailer. php "); // Email sending FunctionFunction smtp_mail ($ sendto_email, $ subject, $ body, $ extra_hdrs, $ user_name ){$ Mail = new PHPMailer ();$

Parse PHP cross-site ticket collection implementation code

Let's talk about the code. Copy codeThe Code is as follows: function curlrequest ($ url, $ postfield, $ referer = '', $ cookie = ''){ // Http://www.jb51.net $ Ip = rand (100,244). '.'. rand (100,244). '.'. rand (100,244). '. rand (100,244 ); $ Ch =

Parse PHP implementation code for calculating page execution time

As follows: Copy codeThe Code is as follows: $ T = new executeTime; Phpinfo (); Class executeTime { Private $ microtime; Public function _ construct (){ $ This-> microtime = microtime (true ); } Public function getNow (){$ This->__

Total Pages: 12780 1 .... 10346 10347 10348 10349 10350 .... 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.