Write beautiful code-separating the background program from the front-end program _php tips

Source: Internet
Author: User
Tags php code
When writing a PHP program, some of the code is used to handle transactions, such as manipulating the database, doing math, and so on, while some other code is just the result of the transaction processing, For example, some PHP code that uses the Echo statement to display results in HTML format in a Web browser, and HTML code that embeds PHP programs directly. First, we should clearly distinguish between the two code, the former called the background program, the latter called the front-end program.


Because PHP is an embedded programming language, that is, all of the PHP code can be embedded in the HTML code, which provides a lot of convenience for programming. However, "extremes", if in a longer program in the PHP code and HTML code mixed writing, which will make the program messy, not conducive to the maintenance and reading of the program. So we need to transplant as much of the PHP code in the HTML code as possible into these programs, encapsulate the code into functions in a specialized file, and then use the INCLUDE statement in the HTML code to include the files and call them in the right place.


This approach makes both HTML code and PHP code easy to read, and because the HTML code needs to be constantly updated, this decoupled method ensures that the daemon is not corrupted.
Unlike the front-end program, the background program is more stable, structured, rarely changed, so it should be carefully designed and managed. In fact, in the design of the program, put a lot of time is worthwhile, "now trees, after the cool", in the future design work will be able to easily use the background program now written.

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.