PHP Basic Syntax

A PHP code start with the <?php //php start and ends with the  ?> tag.

The PHP delimiter <?php //and ?> in the following example simply tells the PHP engine to treat the enclosed code block as PHP code, rather than simple and file extension file name.php 

Every PHP code block  statement ends with a semicolon (;) — this tells the PHP engine that the end of the current statement has been reached.

//Example :-
<?php echo "Hello, world!"; ?>

PHP within HTML

The default file extension for PHP files is ".php". PHP files are plain text files with .php extension. Inside a PHP file you can write HTML like you do in regular HTML pages as well as embed html code  in PHP code for server side execution. 

<!DOCTYPE html> 
<html lang="en">
      <meta charset="UTF-8">
      <title>PHP within HTML</title>
      <h1><?php echo "Hello, Stack !"; ?></h1>

The above example showing how you can use PHP codes within HTML to create dynamic web pages. If you view the source code of the results on web page in your browser, the only difference you will see is the PHP code <?php echo "Hello, Stack!"; ?> has been replaced with the output "Hello, Stack!".

PHP Comments

A comment is simply text that is ignored by the PHP engine. The purpose of comment is to make the long and short code more relevant. It may help other developers (or you in the future when you update the source code any many more) to understand what you were trying to do with the PHP.

Mainly two types of comments

  1. Single line comment
  2. Multiple line comment
Single-line comments: 

how to write, start the comment with a slash followed by an hash tag (#) and double slash (//), like this:

Multiple-line comments:

 how to write multiple-line comments, start the comment with a slash followed by an asterisk (/*) and end the comment with an asterisk followed by a slash (*/), like this:

Stack Overlode is optimized Tutorials and examples for learning and training. Examples might be simplified to improve reading and learning and understand. Tutorials and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using Stack Overlode, you agree to have read and accepted our terms of use, cookie and privacy policy.