PHPThe unique syntax mixes C, Java, Perl, and PHP's self-innovative syntax. It can perform dynamic Web pages more quickly than CGI or Perl. Dynamic pages made with PHP are embedded in HTML documents to execute, compared to other programming languages, and are much more efficient than CGI, which fully generates HTML markup. Here are 10 advanced application tips for PHP.
1, use the Ip2long () and LONG2IP () functions to convert the IP address into an integer store into the database.
This approach reduces storage space to nearly One-fourth (char (15) of 15 bytes to reshape 4 bytes), calculates whether a particular address is within a section of the page is simpler, and speeds up the search and sorting speed (although sometimes just a little bit faster).
2, verify that the domain name exists by using the CHECKDNSRR () function when verifying the email address.
This built-in function verifies that the specified domain name resolves to an IP address. The user comment 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. For those who think their email address is [Url=mailto: "Joeuser@wwwphp.net]" Joeuser@wwwphp.net[/url] "instead of [Url=mailto:" Joeuser@php.net] " Joeuser@php.net[/url] "The guys, this method can be very handy to catch them.
3, if you are using PHP 5 and MySQL 4.1 or higher, consider discarding the mysql_* series function instead of the improved version of the Mysqli_* series function.
A good feature is that you can use preprocessing statements, which can speed up queries if you are maintaining a database-intensive site. Some assessment scores.
4, learn to fall in love with ternary operators.
5, if you feel that there is a reusable part of the project, before you write the next line of code, let's see if the PEAR is already there.
Many PHP programmers know that PEAR is a good repository, although many programmers do not know. This online repository contains more than 400 reusable program fragments that you can instantly use in your program. Unless you say your project is really special, you can always find a PEAR package that saves you time. (See PECL)
6, with Highlight_file () from the dynamic printing out the format of the very beautiful source code.
This function is handy if you're looking for a script to help with the message board and IRC. Of course, be careful not to accidentally leak out your database connection information and passwords and so on.
7, use the error_reporting (0) function to prevent the user 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 in this case is to add error_reporting (0) to the first line of all scripts, or use the Require_once () method. 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/decompress strings before storing large strings in the net database.
This PHP built-in function uses the GZIP algorithm to compress normal text up to 90%. These functions are used whenever I want to read and write fields of BLOB type. The only exception is when I need a full-text search.
9, you get multiple return values from a function by using the "reference" method to pass the parameter.
Like the ternary operator, most programmers trained in formal programming know this technique. But programmers with HTML backgrounds that are larger than Pascal's backgrounds have more or less questioned "can I return multiple values from a function with only one return?" The answer is to precede the variable with a "&" symbol, passed by "reference" rather than "value".
10, fully understand the dangers of "magic quotes" and SQL injection.
I would like to read that the developers here are already well aware of SQL injection. But I'm still listing this here because it's a bit hard to understand. If you haven't heard of this, use the rest of the day for Google and read it.
Through the analysis of this article, I hope to help you.
http://www.bkjia.com/PHPjc/445810.html www.bkjia.com true http://www.bkjia.com/PHPjc/445810.html techarticle PHP's unique syntax mixes C, Java, Perl, and PHP's self-innovative syntax. It can perform dynamic Web pages more quickly than CGI or Perl. Using PHP to make dynamic pages with other programming languages ...