Top 10 tips to improve your PHP application strength _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Top 10 tips to improve your PHP application strength. On the SmashingMagazine website, GlenStansberry proposed ten advanced PHP skills to instantly introduce your PHP programming strength, including SQL injection attacks. DocumentOn the Smashing Magazine website, Glen Stansberry proposed ten advanced PHP skills, which can instantly increase your PHP programming strength, these include the "cheat sheet" of SQL injection attacks, the else section in simplified sentence, the regular expressions, ternary operators, and the Memcached database cache system, the following is a detailed description.

PHP started with an inconspicuous programming language in 1995 and has developed rapidly over the years. now it is one of the most popular network development languages. many popular websites use PHP for development, most programs and website projects are written in this popular language.

Since PHP is so popular, almost no website developer can skip to know PHP. this tutorial is just the first step of PHP learning, the ten excellent skills listed below are required by PHP developers to learn and use them each time they program, these tips can speed up your PHP proficiency, make your code run faster, more concise, and more performance-optimized.

1. SQL injection attack cheating table

SQL injection attacks are a type of annoying thing. it is a security vulnerability that allows hackers to exploit a vulnerability in a program code to sneak into your database. Although this article has nothing to do with MySQL, it is useful for many PHP programs to use the MySQL database. if you want to write a secure code, you can understand what situations need to be avoided.

Furruh Mavituna wrote an interesting SQL injection attack cheating table, one of which is related to PHP and MySQL security vulnerabilities, your program will not be vulnerable to attacks.

2. understand the differences between various comparison operators

Comparison operators are an important part of PHP. Unfortunately, many programmers are not familiar with the differences between them. in fact, according to an article published on the IO Reader website, many PHP developers cannot distinguish the differences between various comparison operators in PHP:

This is extremely important, but many PHP developers do not know the difference between = and =. in essence, = determines whether the two values are equal, PHP will try to convert the data type before comparison, for example: 1 = '1' (true); = then both the value and data type are determined. for example: 1 = '1' (false), developers must quickly understand the usefulness of these operators for common functions such as strpos (), because PHP regards zero as "false 」, without ====, we do not know whether a searched string is at the beginning of a long string or does not exist at all. in many other applications, when the return value is zero, it may not be equal to false.

You can go to the PHP.net website to view a list of various comparison operators.

3. simplify the else section of the sentence

Note that the third and fourth points may reduce the readability of the code, which emphasizes the speed and efficiency. if you do not want to sacrifice the readability of the code, you may have to skip them.

It is usually a good practice to make code simpler and smaller. one of them is to extract the content of the else statement. Christian Montoya has a good example, use short else statements to convert characters.

Common else statements:

Reference content is as follows:
If (this condition)
{
$ X = 5;
}
Else
{
$ X = 10;
}

If the default value of $ x is 10, we start from 10 and do not need to specify its value in the else part.

 
 
Reference content is as follows:
$x = 10;
if( this condition )
{
$x = 5;
}
If (this condition) if (in this case) {($ x = 5; $ x = 5 ;}) other else {($ x = 10; $ x = 10 ;})

Although it seems that there are not many differences, if your program contains many else statements, the accumulative effect will be obvious.

4. discard the parentheses.
As with the simplified else statement, if there is only one expression after the control structure, dropping the parentheses before and after the expression can save some characters. Evolt.org has a clever example of how to reduce brackets.

Reference content is as follows:
If ($ gollum = 'halfling '){
$ Height --;
}

This is the same:
Reference content is as follows:
If ($ gollum = 'halfling') $ height --;
This method can be used multiple times in the program:

Reference content is as follows:
If ($ gollum = 'halfling') $ height --;
Else $ height ++;

If ($ frodo! = 'Dest ')
Echo 'Gosh darnit, roll again Sauron ';

Foreach ($ kill as $ count)
Echo 'legolas strikes again, that MAK'. $ count. 'for me! ';


5. obtain str_replace (), assumereg_replace (), and preg_replace ()

In terms of efficiency, str_replace () is more suitable for replacing strings than regular expressions. according to some studies, str_replace () is 61% more efficient than ereg_replace () and preg_replace.

$ X = 10; $ x = 10; if (this condition) if (in this case) {($ x = 5; $ x = 5 ;})
 
 
  • 2 pages in total:
  • Previous Page
  • 1
  • 2
  • Next page

On the Smashing Magazine website, Glen Stansberry proposed ten advanced PHP skills to instantly introduce your PHP programming strength, including SQL injection attacks...

Related Article

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.