Home  >  Article  >  Backend Development  >  Detailed explanation of PHP code specifications in PHP development specification manual_PHP tutorial

Detailed explanation of PHP code specifications in PHP development specification manual_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:32:21954browse

It involves many aspects, such as PHP code specifications, PHP file naming specifications, website development process, website security and maintenance, etc.
As the beginning of PHP development specifications, I will talk about what I think of PHP code specifications from the perspective of a pure PHP developer, mainly from the three perspectives of PHP directory framework structure, PHP code writing specifications, and PHP file naming specifications. Elaboration, I hope it will be helpful to beginners of PHP.
Reasonably build 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 design of the website directory framework structure is reasonable and standardized, which is not only conducive to website development, but also good for SEO, website Promotion is beneficial.
Generally, the most basic PHP website structure involves images, CSS files, JS files, third-party components, management background, etc. Correspondingly, the basic PHP directory framework structure also involves these contents. There are also standards for naming these directories. For example
Picture directory: images or pic
CSS directory: css
JS directory: js
Third-party component directory: libs or include. The next-level directory can define the directory name according to the specific component name
Management directory: It is usually admin. For security reasons, you can choose another directory name or set password protection for the admin directory. How to password-protect access to directories?
Special reminder: For the framework directory structure of the website, it is necessary to plan it in advance. In order to be friendly to search engines and facilitate website promotion, it is recommended that the directory structure level should not be too deep, and a two- and three-level directory structure will be enough.
In addition, if you use templates, you can create a template directory, for example, name the directory tpl. If you use a third-party template engine, such as smarty, you can decide whether to set up another directory according to your needs. PHP basic tutorial: Smarty installation tutorial
For medium-sized websites, you can also divide the website directory frame structure according to website functions, such as channels.
PHP file naming convention
Good PHP file naming convention is also an element of PHP development specifications, which is helpful for memory and easy to manage. There are also certain rules for naming PHP website program files, such as
PHP website homepage file Naming convention: index.php or index.html
CSS file naming convention: The main CSS file is named style.css. In addition, you can also name it for specific modules or channels. For example, the CSS file for users can be defined as user_style.css or u_style.css
JS file naming convention: the main JS file is named main.js or major.js, and other JS files are named according to specific pages or specific objects, such as the homepage JS file. It can be named index.js, and the JS file that serves user login can be named user_login.js, etc.
Website configuration file naming convention: config.php or default_config.php, etc.
Special reminder for file naming: considering portability when naming PHP files, always use lowercase names, and name them with the website directory name. Similarly, there are two ways to name files. One can use pinyin to name specific files, and the other can use simple and clear English words to name files. Do not name files casually, which will cause confusion in future maintenance.
PHP code writing standards
Good PHP code standards will help PHP introductory learners benefit from the PHP code you write, and will also help you maintain your code in the future.
1. Add necessary code comments to the PHP code you write, and the code comments should be standardized. For more basic PHP code writing specifications, please refer to the PHP basic syntax tutorial
2. Maintain good PHP code writing specifications , use indentation reasonably to keep the code beautiful.
 3. When using the assignment character, the variable name, assignment character, and value are separated by spaces, that is,

Copy the code The code is as follows:

$leapsoulcn = "Welcome to the PHP website tutorial network. This section mainly introduces PHP development specifications and PHP code specifications";
?>

4. When writing if, switch, and function codes, be sure to keep the curly braces matching, that is,
Copy the code The code is as follows:

if(){
...
}
?>

or
Copy code The code is as follows:

if()
{
...
}
?>

5. Pay attention to code writing standards when naming variable names or function names. You can use pinyin, English words, abbreviations, etc. It is recommended to use English words as the PHP code naming standards. For both More than two words are connected with an underscore or the first letter of one of the words is capitalized, that is,
Copy the code The code is as follows:

$web_name = "PHP website development tutorial network";
$webUrl = "http://www.jb51.net";
function userLogin()
{
}
?>

The above are the basic PHP code specifications, which will be helpful for PHP beginners to learn PHP. Developing good PHP coding standards will benefit developers throughout their lives.
At this point, the PHP code specification of the PHP Development Specification Manual has been introduced. Good website framework directory construction capabilities, PHP file naming specifications and PHP code writing specifications need to be accumulated and developed through continuous development. At the same time, these development specifications It also helps cooperation between partners and helps PHP introductory learners learn your PHP code.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322846.htmlTechArticleInvolves many aspects, such as PHP code specifications, PHP file naming specifications, website development process, website security and maintenance, etc. . As the beginning of PHP development specifications, I will start from the perspective of a pure PHP developer...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn