10 practical advanced PHP application tips _ PHP Tutorial

Source: Internet
Author: User
Very practical 10 advanced PHP application skills. The unique PHP syntax is a mix of C, Java, Perl, and PHP self-innovative syntaxes. It can execute dynamic web pages more quickly than CGI or Perl. Dynamic pages made using PHP are a mix of C, Java, Perl, and PHP self-innovative syntaxes with the unique syntax of PHP in other programming languages. It can execute dynamic web pages more quickly than CGI or Perl. Compared with other programming languages, PHP embeds programs in HTML documents for execution on dynamic pages made using PHP, which is much more efficient than generating CGI with HTML tags completely. The following describes ten advanced PHP application skills.

1. use the ip2long () and long2ip () functions to convert the IP address into an integer and store it in the database.

This method reduces the storage space to nearly 1/4 (15 bytes of char (15) to 4 bytes of integer ), it is easier to calculate whether a specific address is on a page in a specific segment, and it accelerates search and sorting (although sometimes only a little faster ).

2. when verifying the email address, use the checkdnsrr () function to verify whether the domain name exists.

This built-in function can confirm that the specified domain name can be resolved to an IP address. The user comment section of the PHP document for this function has a simple user-defined function, which is based on checkdnsrr () to verify the legitimacy of the email address. For those email addresses that think they are [url = mailto: "joeuser@wwwphp.net]" joeuser@wwwphp.net [/url] "instead of [url = mailto: "joeuser@php.net]" joeuser@php.net [/url] "people, this method can easily catch them.

3. if you are using PHP 5 and MySQL 4.1 or a later version, consider abandoning mysql _ * series functions to use MySQL _ * series functions of mysql and MySQL.

A good feature is that you can use preprocessing statements. if you are maintaining a database-intensive site, this feature can speed up the query. Some evaluation scores.

4. learn to fall in love with ternary operators.

5. if you feel reusable parts in the project, check whether PEAR already exists before writing a line of code.

Many PHP programmers know that PEAR is a good resource library, although many programmers do not know. This online resource library contains more than 400 reusable program fragments that you can immediately use in your program. Unless your project is really special, you can always find the PEAR package that helps you save time. (See PECL)

6. use highlight_file () to automatically print the beautifully formatted source code.

If you seek help from a script on the message board or IRC, this function is very handy. Of course, be careful not to accidentally disclose your database connection information and password.

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

Ideally, the publishing server should be completely disabled in php. ini. However, if you are using a shared web server, you do not have your own php. ini file. in this case, you 'd better choose to add error_reporting (0) before the first line of all scripts (or use the require_once () method ). This completely blocks sensitive SQL query statements and path names when an error occurs.

8. before storing large strings in the database, use gzcompress () and gzuncompress () to explicitly compress/decompress the strings.

This PHP built-in function uses the gzip algorithm to compress common text by up to 90%. These functions are used every time I want to read and write BLOB fields. The only exception is when I need full-text retrieval.

9. multiple return values are obtained from a function using the "reference" parameter passing method.

Like the ternary operator, most programmers who have been formally trained in programming know this technique. However, programmers whose HTML background is greater than the Pascal background have more or less such questions: "How many values can be returned from a function when only one return can be used ?" The answer is to add the "&" symbol before the variable and pass it through "reference" instead of "value.

10. fully understand the risks of "magic quotes" and SQL injection. Www.2cto.com

I hope all the developers here will be familiar with SQL injection. However, I still put this article here because it is hard to understand. If you have never heard of such a statement, use the rest of today for Google and reading.

Through the analysis in this article, we hope to help you.


From Crazy Coding life of Heda Li Xin

The unique syntax of http://www.bkjia.com/PHPjc/478393.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478393.htmlTechArticlePHP is a mix of C, Java, Perl, and PHP self-innovative syntax. It can execute dynamic web pages more quickly than CGI or Perl. Dynamic pages made using PHP and other programming languages...

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.