Basic PHP Syntax with Examples

A PHP is a server side scripting language, PHP is run on the server, and the plain HTML result is returned back to the browser. A PHP code can be placed anywhere in the document.

PHP Syntax with Examples

PHP code must be contained in special tags so that the PHP interpreter can identify it. Depending on the PHP configuration, these tags can take several forms:

The universally effective PHP tag style is

Short-open (SGML-style) tags enabled via the short_open_tag php.ini configuration file directive.

HTML or Script style tags

ASP-style tags enabled via the asp_tags php.ini configuration file directive

The default file extension for PHP files is “.php”.

PHP Syntax with Examples

Note: PHP statements end with a semicolon (;). The semicolon is a separator and is used to distinguish one set of instructions from another. With PHP, there are two basic statements to output text in the browser: echo and print.

Read More – PHP Programming Language Tutorial For Beginners!

 

 

PHP Syntax with Examples

 

Commenting PHP Code

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.

PHP has two forms of comments:

  • Single-line comments begin with a double slash (//).
  • Multi-line comments begin with “/*” and end with “*/”.

– Comments can be used to let others understand what you are doing

– Remind yourself of what you did – Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code

Thanks 🙂

Digital Technology Hub