10 PHP Some obscure advanced application tips _php Tutorials

Source: Internet
Author: User
Tags pear
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. 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. This function can be used to query the PHP Help document for its specific use.

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. This is a conclusion based on 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, then your best bet in this case 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/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 to Google, read, and visit the PHP Programmer's note site.

http://www.bkjia.com/PHPjc/371828.html www.bkjia.com true http://www.bkjia.com/PHPjc/371828.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 ...

  • 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.