Updated syntax, corrected and added information. (#19433)
Updated syntax to adhere to PSR, corrected outdated information, and added additional information regarding tags and indentation.
This commit is contained in:
		
				
					committed by
					
						
						Quincy Larson
					
				
			
			
				
	
			
			
			
						parent
						
							c614c91f8a
						
					
				
				
					commit
					cedb5befd9
				
			@@ -2,42 +2,65 @@
 | 
			
		||||
title: PHP Syntax and Comments
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
### PHP Syntax
 | 
			
		||||
## PHP Syntax
 | 
			
		||||
 | 
			
		||||
The structure of a PHP syntax somewhat looks like:
 | 
			
		||||
The structure of a PHP document may look something like:
 | 
			
		||||
 | 
			
		||||
```shell
 | 
			
		||||
```
 | 
			
		||||
<?php
 | 
			
		||||
    
 | 
			
		||||
// Your PHP code goes here.
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**NOTE:** When creating a document with only PHP, the closing tags (see below) should be omitted.
 | 
			
		||||
 | 
			
		||||
When placing PHP in an HTML document, a closing tag is needed, like so:
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
// Your PHP code goes here.
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
```
 | 
			
		||||
This PHP script can be placed anywhere in the document.
 | 
			
		||||
A PHP file generally have HTML tags, and some scripting code .
 | 
			
		||||
 | 
			
		||||
**NOTE:** Shorthand syntax is also available, but should be avoided to reduce unwanted behavior.
 | 
			
		||||
 | 
			
		||||
A PHP file may have HTML tags and / or JavaScript.
 | 
			
		||||
 | 
			
		||||
The default file extension for PHP files is `.php`.
 | 
			
		||||
 | 
			
		||||
 ### How to make comments in PHP?
 | 
			
		||||
## Indentation
 | 
			
		||||
 | 
			
		||||
A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is looking at the code.
 | 
			
		||||
While this is mostly personal preference, it is most common to see the lines within the <?php / ?> tags at the same level, like so:
 | 
			
		||||
 | 
			
		||||
In PHP, comments can be make by two ways either single lined or multi-lined.
 | 
			
		||||
The code snippet given below explains it:
 | 
			
		||||
```
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
```shell
 | 
			
		||||
<?
 | 
			
		||||
   // This is a single-line comment
 | 
			
		||||
 | 
			
		||||
    # This is also a single-line comment
 | 
			
		||||
 | 
			
		||||
   /*
 | 
			
		||||
     This is a multiple-lines comment block
 | 
			
		||||
     that spans over multiple
 | 
			
		||||
     lines
 | 
			
		||||
   */
 | 
			
		||||
?>
 | 
			
		||||
// Same level of indendation.
 | 
			
		||||
    // Not indented like so.
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
### More information
 | 
			
		||||
## How to make comments in PHP?
 | 
			
		||||
 
 | 
			
		||||
For more resources you can visit: https://www.w3schools.com/php/php_syntax.asp
 | 
			
		||||
A comment in PHP code is a line that is not executed as part of the program. Its only purpose is to be read by someone who is looking at the code.
 | 
			
		||||
 | 
			
		||||
In PHP, comments can be make by two ways — either single-lined or multi-lined.
 | 
			
		||||
 | 
			
		||||
This can be seen in the example below:
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
<?
 | 
			
		||||
 | 
			
		||||
// This is a single-lined comment.
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This is a multi-lined comment block
 | 
			
		||||
 * that spans over multiple
 | 
			
		||||
 * lines.
 | 
			
		||||
 */
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Additional Information
 | 
			
		||||
 | 
			
		||||
For more information, please see [PHP: Comments](http://php.net/manual/en/language.basic-syntax.comments.php).
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user