10 PHP Some unknown advanced application techniques

Source: Internet
Author: User

PHP's unique syntax mixes C, Java, Perl, and PHP with its own innovative syntax. It can execute dynamic Web pages faster than CGI or Perl. Dynamic pages made with PHP compared to other programming languages, PHP embeds programs into HTML documents and executes more efficiently than CGI that completely generates HTML tags. Here are 10 advanced PHP application tips.

1, use the Ip2long () and the Long2ip () function to convert the IP address into an integral type stored in the database.

This approach minimizes storage space to nearly One-fourth (4 bytes of 15 bytes of char (15)), calculating whether a particular address is simpler in one section, and speeding up search and sorting (though sometimes just a little faster).

2, when verifying the email address, use the CHECKDNSRR () function to verify the existence of the domain name.

This built-in function confirms that the specified domain name resolves to an IP address. The user comments section of the PHP document for this function has a simple user-defined function that is based on CHECKDNSRR () to verify the legality of the email address. The specific use of this function can be used to query the PHP help document.

3, if you are using PHP 5 and MySQL 4.1 or higher, consider discarding the mysql_* series functions instead of the improved version of the Mysqli_* series functions.

A good feature is that you can use preprocessing statements, and if you are maintaining a database-intensive site, this feature can speed up the query. This is based on a number of assessment points to draw conclusions.

4, learn to love the ternary operator.

5, if you feel a reusable part of the project, see if it already exists in PEAR before you write down a line of code.

Many PHP programmers know that PEAR is a good repository, although many programmers do not know it. This online repository contains more than 400 reusable pieces of program that you can use immediately with a knife in your program. Unless your project is really special, you can always find a PEAR bag that helps you save time. (See PECL)

6, with Highlight_file () from the dynamic print out of the formatted very beautiful source code.

This function is handy if you're looking for a script help on the message board, IRC, and other places. Of course, be careful not to accidentally leak out your database connection information and password and so on.

7, use the error_reporting (0) function to prevent users from seeing potentially sensitive error messages.

Ideally, the publisher should be completely banned in php.ini. But if you're using a shared Web server and you don't have your own php.ini file, your best bet is to add error_reporting (0);(or use the require_once () method before the first line of all the scripts. This makes it possible to completely block sensitive SQL query statements and path names when errors occur.

8, use Gzcompress () and gzuncompress () to explicitly compress/extract strings before storing large strings in the Web database.

This PHP built-in function uses the GZIP algorithm to compress ordinary text up to 90%. I use these functions every time I want to read and write to a BLOB type field. The only exception is when I need full text search.

9, you can get multiple return values from a function by passing arguments by reference.

Like ternary operators, most programmers trained in formal programming know this technique. But those with a more HTML background than Pascal have more or less the question of "returning multiple values from a function when only one return can be used?" The answer is to precede the variable with a "&" symbol passed by reference rather than by "value."

10, fully understand the "magic quotes" and the dangers of SQL injection.

I hope that the developers who read here are already injecting and understanding SQL. But I still put this one here because it's really hard to understand. If you've never heard of this, spend the rest of the day with Google, read, and visit the PHP Programmer's Notebook site.

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.