Showing posts with label PHP Syntax. Show all posts
Showing posts with label PHP Syntax. Show all posts

Friday, 22 July 2022

PHP Syntax

Basic PHP syntax, including case sensitivity, statements, and whitespaces.

As a programming language, PHP has a set of rules that governs how you write programs.

Start PHP 

<?php

Enclosing tag

?>

Example

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>PHP Syntax</title> </head> <body> <h1><?php echo 'PHP Syntax'; ?></h1> </body> </html>


 PHP code, the enclosing tag is optional

<?php echo 'PHP Syntax';


PHP is partially case-sensitive. Knowing what is case sensitive and what is not is crucial to avoid syntax errors.

If you have a function such as, you can use it as COUNT. It would work properly.

The following are case-insensitive in PHP:

  • PHP constructs are if, if-else, if-else, switch, while, do-while, etc.
  • Keywords such as true and false.
  • User-defined function & class names.

On the other hand, variables are case-sensitive. e.g., $message and $MESSAGE are different variables.

A PHP script typically consists of one or more statements. A statement is a code that does something, e.g., assigning a value to a variable and calling a function.

A statement always ends with a semicolon (;). The following shows a statement that assigns a literal string to the $message variable:

$message = "Hello";PHP also has a compound statement that consists of one or more simple statements.if( $is_new_user ) { send_welcome_email(); }The closing tag of a PHP block (?>) automatically implies a semicolon (;). Therefore, you don’t need to place a semicolon in the last statement in a PHP block. For example:<?php echo $name ?>The statement echo $name doesn’t need a semicolon. However, using a semicolon for the last statement in a block should work fine. For example:<?php echo $name; ?>

Whitespace & line breaks

In most cases, whitespace and line breaks don’t have special meaning in PHP. Therefore, you can place a statement in one line or span it across multiple lines.

login( $username, $password );


login( $username, $password );






























o";










Microsoft Thwarts Chinese Cyber Attack Targeting Western European Governments

  Microsoft on Tuesday   revealed   that it repelled a cyber attack staged by a Chinese nation-state actor targeting two dozen organizations...