10 things you don't know about PHP-PHP source code

Source: Internet
Author: User
Ec (2); 1. Use ip2long () and long2ip () to store IP addresses to the database in integer mode, rather than string mode. This will reduce the storage space by almost half (char (15) 15 bytes, integer is 8 bytes), and it is easier to calculate whether an IP address is within a range. It also accelerates search and sorting. 2. Apply checkdnsrr () to check whether the domain name exists and verify part of the email address. Script ec (2); script

1. Use ip2long () and long2ip () to store IP addresses to the database in integer mode, rather than string mode. This will reduce the storage space by almost half (char (15) 15 bytes, integer is 8 bytes), and it is easier to calculate whether an IP address is within a range. It also accelerates search and sorting.

2. Apply checkdnsrr () to check whether the domain name exists and verify part of the email address. This checkdnsrr () built-in function can query DNS records through the corresponding domain name or IP address. Some PHP developers use this function to write a custom function that can verify part of the email address. Click to view details. Please note that this function has not been implemented on windows platform! Use Net_DNS In the PEAR library instead.

3. If you use a combination of PHP 5 + MySQL 4.1 or a later version, try the improved mysqli _ * function instead of the mysql _ * function. A superior feature of the mysqli _ * function is that prepared statements can be used. If you maintain a website that is highly dependent on the database, this function will greatly increase the database query speed. If you don't believe it, you can read this performance test article-MySQLi vs MySQL. The final result is mysqli_stmt> mysql_query> mysqli_query> mysqli_multi_query. Mysqli_stmt is the best.

4. Learn to use ternary operator ). That is, replace the if/else Condition Statement with "?" : "Indicates.

5. You don't have to recreate the wheel. First, check if anyone in the PEAR library has invented the wheel.

6. highlight_file () can format your code, which is beautiful.

7. Use the error_reporting (0) function to prevent potential sensitive error messages from being displayed to users. The best case is to configure the php. ini file on the server to directly block the display of error reports. However, if you use a VM, you will not be lucky enough to edit and modify the php. ini file. You must use another method: add the error_reporting (0); statement in the first line of php code. The advantage is that these sensitive error messages, such as SQL query statements and server physical paths, are not displayed to users.

8. Before storing a large amount of string text into the database, use gzcompress () and gzuncompress () for compression and decompression conversion. This built-in function uses the gzip algorithm to increase the text compression rate by more than 90%. Of course, full-text search cannot be performed after compression.

9. You can use "reference transfer" in parameter transfer of a function to return multiple values. Programmers with programming language basics know this usage in other languages. However, some web designers who only use the html language are confused. The answer is to use the "&" symbol to process variables and pass them by reference instead of by value.

<

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.