PHP code specification in the PHP development specification manual

Source: Internet
Author: User
Tags php website php website tutorial password protection

It involves multiple aspects, such as PHP code specifications, PHP File naming rules, website development processes, and website security and maintenance.
As the beginning of the PHP development specification, I refer to what I think is the PHP code specification from the perspective of a pure PHP developer, this article mainly describes the PHP Directory framework structure, PHP code writing specifications, and PHP File naming rules, hoping to help PHP beginners.
Reasonably construct the PHP Directory Framework Structure
We know that before using PHP for website development, we need to build the directory structure of the website. The website directory framework structure is properly designed and standardized, which is not only conducive to website development, but also for SEO, website promotion is beneficial.
Generally, the most basic PHP website structure involves images, CSS files, JS files, third-party components, and management backend. Correspondingly, the basic PHP Directory framework structure also involves such content, these directories are also standardized, such
Image Directory: images or pic
CSS Directory: css
JS Directory: js
Third-party component directory: libs or include. The directory name can be defined based on the specific component name in the next level.
Management Directory: admin is used generally. For security reasons, you can set a new directory name or set password protection for the admin directory. How do I set password protection for access directories?
Note: You must plan the directory structure of the website framework in advance. In order to be friendly to search engines and facilitate website promotion, we recommend that you do not have a deep directory structure level. You can use the level 2 and level 3 directory structure.
In addition, if you use a template, you can create a template directory, such as naming the directory as tpl. If you use a third-party template engine, such as smarty, you can decide whether to set a directory as needed. PHP basic Tutorial: Smarty installation tutorial
For medium-sized websites, you can also divide the website directory framework structure based on the website functions, such as by channel.
PHP File naming rules
A good PHP File naming convention is also an element of PHP development specifications, which helps to remember and facilitate management. PHP website program files also have certain naming rules, such
PHP homepage File naming rules: index.phpor index.html
CSS file naming rules: CSS
JS File naming rules: the main JS file is named main. js or major. js. You can name other JS files based on specific pages or specific objects. For example, the JS file on the homepage can be named index. js. The JS file used for user login can be named user_login.js.
Naming rules for website configuration files: config. php or default_config.php
Special reminder for file naming: when naming PHP files with portability in mind, please use lower-case names. In addition, like the website directory name, two file naming methods can be used, A specific file can be named in pinyin, and a simple and clear English Word Naming file can be used. Do not name it casually, resulting in confusion in future maintenance.
PHP code writing specifications
A good PHP code specification helps beginners of PHP to benefit from the PHP code you write and facilitate code maintenance in the future.
1. Add necessary code comments for the written PHP code, and standardize the code comments. For more basic PHP code writing standards, see the PHP basic syntax tutorial.
2. Maintain good PHP code writing specifications, use indentation properly, and keep the code beautiful.
3. When the value assignment operator is used, the variable name, value assignment operator, and value are separated by spaces, that is Copy codeThe Code is as follows: <?
$ Leapsoulcn = "welcome to the PHP website tutorial network. This section mainly introduces PHP code specifications in PHP development specifications ";
?>

4. When writing if, switch, and function code, make sure that the braces match, that isCopy codeThe Code is as follows: <?
If (){
......
}
?>

OrCopy codeThe Code is as follows: <?
If ()
{
......
}
?>

5. Pay attention to code writing specifications when naming variable names or function names. You can use Pinyin, English words, abbreviations, and other forms. We recommend that you use English words as PHP code naming rules, the following dashes of two or more words are connected or the first letter of one word is capitalized, that isCopy codeThe Code is as follows: <?
$ Web_name = "PHP website development tutorial network ";
$ WebUrl = "http://www.jb51.net ";
Function userLogin ()
{
}
?>

The above is the basic PHP code specification, which will be helpful for PHP beginners to learn PHP. Developing a good PHP code specification will benefit developers for a lifetime.
So far, PHP code specifications in the PHP development specification manual have been introduced, good website framework directory construction capabilities, PHP File naming rules, and PHP code writing specifications need to be accumulated and developed in constant development. At the same time, these development specifications are also conducive to cooperation between partners, help PHP beginners learn your PHP code.

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.