PHP Development Considerations Summary, PHP Development Considerations _php Tutorial

Source: Internet
Author: User

PHP Development Considerations Summary, PHP development considerations


1. Use the embedded HTML code instead of the Echo statement in PHP.

Because PHP is an embedded web programming language, you can embed HTML code and PHP code with each other. But many programmers worry that too much of the "" embedded PHP code in the HTML code will invoke the PHP interpreter multiple times, thereby reducing the speed of PHP code, preferring to use the Echo statement of PHP to output HTML code instead of using HTML code directly. But the exact opposite is true. Each PHP page only calls the PHP interpreter to explain all the PHP code, so, only when needed to embed the PHP code, and most of the time the direct use of HTML code input results, not only will not reduce the speed of the program, but also because of the reduction of ECHO statement parsing, It is often possible to increase the speed of code running.

2. Try to use Str-replace instead of Ereg-replace

Programmers who are accustomed to programming with Perl are more likely to use ereg_replace to do string substitution work, because the use of ereg_replace in PHP is similar to that of pattern matching in Perl. However, the following code proves that using Str_replace instead of ereg_replace can greatly improve the speed of your code.

3. Note the reference to the string

PHP, like many other programming languages, can use double quotation marks ("") to refer to a string, or you can use single quotation marks (). In PHP, however, if you use double quotation marks to refer to a string, the PHP parser will first parse the string with a reference to the variable and replace it with a variable. If it's a single quote, it's not so complicated--just display all the strings that enclose the single quotation marks directly. Obviously, in PHP programming, it is quicker to use single quotation marks to refer to string variables than to use double quotes.

4. Determine the maximum number of cycles before executing the For loop, and do not calculate the maximum value once per loop

Copy the Code code as follows:

5. Note the difference between include and require

In PHP, the Include () function is the same as require (), but there are some differences in usage, include () is conditional include function, and require () is an unconditional include function. For example, in the following example, if the variable $somgthing is true, the file will be included Somefile

Copy the Code code as follows:
if ($something) {
Include ("Somefile.txt");
}
However, regardless of the $something value, the following code will include the file somefile into the file:
if ($something) {
Require ("Somefile.txt");
}

6. Do the database query operation, should try to avoid joint operation

PHP has a very powerful database function compared to other Web programming languages.
However, in PHP the operation of the database is still a very time-consuming task, so, as a web programmer, to minimize the database query operations, and should establish a proper index for the database.
Another notable thing is that when working with a database in PHP, it is possible not to use multiple data tables for federated operations, although federated operations can enhance the query functionality of the database, but it greatly increases the burden on the server.

7. If you want to know when the script starts executing (that is, when the server receives the client request), use $_server[' request_time ') to get used to the time () function.

8. Object-oriented is not necessarily necessary, and objects are more time-consuming . There are some simple operations that are quick to process.

9. $row [' ID '] at 7 times times the speed of $row[id]

10.echo is faster than print , and uses Echo's multiple parameters (meaning: a comma instead of a period) instead of a string connection

Like Echo $str 1, $str 2.

11. When If...else ... When nesting is relatively long, you should choose Switch....case

12. Release the unused MySQL query results in a timely manner (Mysql_free_result ())

The difference between 13.isset () and Empty ()

Both are used to test variables.
But Isset () is a test of whether a variable is assigned, and empty () tests whether a variable that has been assigned is empty
If a variable is not assigned the reference is allowed in PHP, but there is a notice hint
If a variable is assigned a null value, $foo = "" or $foo=0 or $foo =false, then empty ($foo) returns True, Isset ($foo) also returns true, meaning that the null value does not unregister a variable.

To unregister a variable, you can use Unset ($foo) or $foo=null

The above is the whole content of this article, I hope you can enjoy.

http://www.bkjia.com/PHPjc/953144.html www.bkjia.com true http://www.bkjia.com/PHPjc/953144.html techarticle PHP Development Considerations Summary, PHP Development considerations 1. Use the embedded HTML code instead of the Echo statement in PHP. Because PHP is an embedded web programming language, you can put HTML code and ph ...

  • 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.