PHP code specification in the PHP development specification manual

  • 2020-03-31 21:26:32
  • OfStack

It covers many aspects, such as PHP code specification, PHP file naming specification, website development process, website security and maintenance, etc.
As the beginning of the PHP development specification, I from the point of view of a pure PHP developer to say what I think of the PHP code specification, mainly from the PHP directory framework structure, PHP code writing specification, PHP file naming specification three aspects to elaborate, hope to help PHP beginners.
Reasonable construction of PHP directory frame structure
We know in the use of PHP website development, we need to build the directory structure of the site, the site directory framework structure is designed reasonably standard, not only conducive to the development of the site, but also for SEO, website promotion are beneficial.
In general, the most basic PHP website structure involves images, CSS files, JS files, third-party components, management background and other content, corresponding to the basic PHP directory framework structure also involves these content, these directory naming also have specifications, such as
Images or PIC
CSS directory: CSS
JS directory: JS
Third party component directories: libs or include, the next level of directory can be defined according to the specific component name
Admin directory: generally is admin, the unit of security, you can give another directory name or admin directory password protection. How do I password protect an access directory?
Special reminder: for the site's framework directory structure, to do a good job of planning in advance, in order to search engine friendly for the site promotion, it is recommended that the directory structure hierarchy is not too deep, two or three levels of directory structure can be.
In addition, if you use templates, you can create a template directory, such as TPL, and if you use a third-party template engine, such as smarty, you can decide whether to set up another directory as needed. Basic PHP tutorial: Smarty installation tutorial
For mid-sized sites, you can also break down your site's directory structure by function, such as by channel.
PHP file naming conventions
A good PHP file naming specification is also an element of PHP development specification, which helps to remember, easy to manage, PHP website program file naming also has certain rules, such as
PHP website home page file naming specification: index.php or index.html
CSS file naming: the main CSS file is named style.css, and you can also name specific modules or channels, such as CSS files for users, as user_style.css or u_style.css
JS file naming specification: the main JS file named main.js or major.js, other JS file named, you can according to the specific page or specific object named, such as the home page JS file can be named as index.js, service to the user login JS file can be named as user_login.js.
Website configuration file naming specification: config.php or default_config.php
File named special remind: in the PHP file name when considering the portability, all use lowercase names, in addition to web directory name, file name can be used in two ways, one can use pinyin specific file name, a name can use simple English words file, do not call, leading to confusion in the future maintenance.
PHP code writing specification
Good PHP code specification, help PHP beginners to benefit from the PHP code you write, and help your future code maintenance.
1, for the written PHP code, add the necessary code comments, and code comments to specification, more basic PHP code writing specification, please refer to the basic PHP grammar tutorial
2. Maintain good PHP code writing standards, use indentation reasonably, and keep the code beautiful.
3. When using the assignment character, the variable name, the assignment character and the value are separated by a space, that is
 
<? 
$leapsoulcn = " Welcome to visit PHP Website tutorial net, this section mainly introduces PHP Development specification PHP Code specification "; 
?> 

4. When writing if, switch and function code, make sure that the braces match, i.e
 
<? 
if(){ 
...... 
} 
?> 

or
 
<? 
if() 
{ 
...... 
} 
?> 

5. When naming variable names or function names, pay attention to the code writing standard, you can use pinyin, English words, abbreviations and other forms, it is recommended to use English words as the PHP code naming standard, for two words or more than the underline connection or the first letter of one of the word capitalized form, namely
 
<? 
$web_name = "PHP Website development tutorial net "; 
$webUrl = "//www.jb51.net"; 
function userLogin() 
{ 
} 
?> 

Above is the basic PHP code specification, for PHP beginners to learn PHP will be helpful. Developing good PHP code specifications will benefit developers for the rest of their lives.
At this point, PHP code handbook of PHP code standard is introduced, good ability of website building framework directory, PHP file naming conventions, and PHP code written specification need their accumulation and develop in the unceasing development, at the same time the development specification also contribute to the cooperation between partners, helps PHP portal learners learn your PHP code.

Related articles: