Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Code writing and file naming specification for PHP development

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "PHP development code writing and file naming specification". In daily operation, I believe that many people have doubts about PHP development code writing and file naming standards. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "PHP development code writing and file naming specification". Next, please follow the editor to study!

Understanding PHP development specifications can reduce many detours, and there are many kinds of PHP development specifications on the Internet. Combined with my own use of PHP, I will talk about my understanding of PHP development specifications, involving many aspects, such as PHP code specification, PHP file naming specification, website development process, website security and maintenance, and so on.

As the beginning of PHP development specification, I talk about what I think of PHP code specification from the perspective of a pure PHP developer, mainly from three angles: PHP directory framework structure, PHP code writing specification and PHP file naming specification. I hope it will be helpful to the beginner of PHP.

Reasonable Construction of PHP Catalog Framework

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 beneficial to the website development, but also beneficial to SEO and website promotion.

Generally, the most basic PHP website structure involves pictures, CSS files, JS files, third-party components, management background and so on. Correspondingly, the basic PHP directory framework structure also involves these contents. There are also specifications for naming these directories, such as

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.

Manage directories: usually admin, for security reasons, you can name another directory or set password protection for the admin directory. How do I set password protection for an access directory?

Special reminder: for the framework directory structure of the website, we should make a good plan in advance. In order to be friendly to the search engine and facilitate the promotion of the website, it is recommended that the level of the directory structure is not too deep, and the second and third level directory structure is fine.

In addition, if you use a template, 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 or not to set up another directory as needed.

For medium-sized websites, you can also divide the website directory framework structure according to the website function, such as by channel and so on.

PHP file naming convention

A good naming convention for PHP files is also an element of the PHP development specification, which is helpful to memory and easy to manage. There are also certain rules for naming program files on PHP websites, such as

PHP website home page file naming convention: index.php or index.html

CSS file naming convention: the main CSS file is named style.css, and you can also name it for a specific module or channel. 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, other JS files are named, you can name according to a specific page or a specific object, such as the home JS file can be named index.js, JS files that serve user login can be named user_login.js, and so on.

Website profile naming convention: config.php or default_config.php, etc.

File naming special reminder: when naming PHP files taking into account portability, all please use lowercase naming, and site directory naming, file naming can be used in two ways, one can use Pinyin to name specific files, a simple and clear English word can be used to name files, do not casually name, leading to future maintenance confusion.

PHP code writing specification

A good PHP code specification will help beginner PHP learners benefit from the PHP code you write and help you maintain your code in the future.

1. For the written PHP code, add the necessary code comments. At the same time, the code comments should be standardized. For more basic PHP code writing specifications, please refer to the PHP basic Grammar course.

2. Maintain a good PHP code writing standard, use indentation reasonably, and keep the code beautiful.

3. When using an assignment character, the variable name, assignment character, and value are separated by spaces, that is,

4. When writing if, switch and function code, be sure to keep curly braces matching, that is,

Or

5. Pay attention to the code writing rules when naming variable names or function names. You can use pinyin, English words, abbreviations and other forms. It is recommended to use English words as the PHP code naming specification. For the underscore connection of more than two words or the capitalization of one of the words, that is,

At this point, the study of "code writing and file naming conventions for PHP development" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report