PHP Basics: Syntax
About PHP:
PHP is a server side scripting language that does something in response to events unlike a programming language that can do things even when itâs not responding to events. JavaScript is an example of another popular scripting language but unlike JavaScript, PHP is going to run on the server side (Web Server) not on the client side (User Browser).
Because PHP run on the server side, that means, that it generally canât run on its own and we are going to need a Web server in order to run it, but itâs going to run as-is, witch means that it doesnât need to be compiled like other programming language such as C or JAVA programs.
PHP is designed to work with HTML. It can be embedded within HTML, can be used with HTML and at the end PHP is going to return HTML to the browser.
PHP Syntax:
To differentiate PHP code from HTML, a PHP scripting block can be written in between a four types of tag.
Standard Tag:
Short Tag:
Script Tag:
-
<script language=âphpâ>
-
echo $variable;
-
</script>
ASP Tag:
NB: It is strongly recommended to use the standard tag when coding in PHP, use of short tag or ASP tag requires you to update you php.ini setting.
PHP Comments:
A PHP Comment is a line of code that is not going to be interpreted by the server. Its only purpose is to give somebody who is reading the code a description on what the code is intended to do or trying to accomplish…etc. Comments are always a good practice in scripting or programming languages.
In PHP, just like in any other language, there are several ways on how to add comments to you script.
We either use // or # to make a single-line comment or /* and */ to make a multi-line comment.
-
<?php
-
/**
-
* PHP Multi-line Comment
-
*
-
* Author: Joe Black
-
*/
-
-
// This is a single-line comment
-
$variable = ââ;
-
-
function foo() {
-
# This is another single-line comment
-
echo $variable;
-
…
-
?>
-
You think there is more, let us know
Comments
One Response to “PHP Basics: Syntax”



[...] Syntax [...]