Home  >  Article  >  Backend Development  >  The php language supports several comment styles

The php language supports several comment styles

青灯夜游
青灯夜游Original
2022-02-15 14:05:194873browse

php language supports 3 comment styles: 1. C style, using the "//" symbol and the syntax "//comment content"; 2. C language style, using the "/* */" symbol and the syntax "/* Comment content */"; 3. Shell style (Perl style), using the "#" symbol and the syntax "#Comment content".

The php language supports several comment styles

The operating environment of this tutorial: windows7 system, PHP version 8.1, DELL G3 computer

PHP supports 3 comment styles: C, C and Unix Shell style (Perl style)

① Single-line comment (C style), symbol: //

②Multi-line comment (C style), symbol: /* */

③Special single-line comments (not commonly used, Shell style), symbol:

#1. C-style (//) comments

This kind of comment cannot appear ?> mark. If the short_open and asp_tag settings are turned on, &gt ; and %> also cannot appear in comments

<?php
echo "单行注释" ;//一般在代码右边少量说明或写在代码前面使之失效
?>

2. C language style (/* */), nested comments are not allowed

<?php
echo "多行注释" ;
echo "多行注释" ;
/*
一般说明脚本的相关信息,如版本,版权,作者日期等
使一长段代码失效
*/
?>

C-style comments will end when encountering the first "*/", so multi-line comments cannot be nested, otherwise a syntax error will be reported.

3. Shell style (#), same as C ban

<?php
echo "单行注释" ;#一般在代码右边少量说明或写在代码前面使之失效
?>

The three comment styles are as follows

The php language supports several comment styles

Note: Single-line comments are only commented to the end of the line or the current PHP code block ("?>" at the end of the line will not be commented, and PHP encounters "?> " will jump out of PHP mode, and then parse HTML code or other)

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of The php language supports several comment styles. For more information, please follow other related articles on the PHP Chinese website!

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