You may not know about 10 things in PHP. On the other hand, you can use a simple line of code to solve a problem. The following are some cool features that you probably haven't noticed: using ip2long () and long2ip () functions, on the other hand, you can use a simple line of code to solve a problem.
The following are some cool features that you may not have noticed:
Use the ip2long () and long2ip () functions to convert an 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 ).
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 who think their e-mail address is "joeuser@wwwphp.net" rather than "joeuser@php.net", this method can easily catch them.
If you are using PHP 5 and MySQL 4.1 or a later version, consider abandoning the mysql _ * series functions and switching to the MySQL _ * series functions of the mysql version. 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.
Learn to fall in love with ternary operators.
If you feel that there are 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)
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.
Use the error_reporting (0) function to prevent users from seeing 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.
Before storing a large string in a database, use gzcompress () and gzuncompress () to explicitly compress/decompress the string. 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.
You can use the "reference" method to pass parameters to obtain multiple return values from a function. 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.
Fully understand the risks of "magic quotes" and SQL injection. 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.
Bytes. Below are some cool features that you may not have noticed: using ip2long () and long2ip () functions...