Powered by Tech-Attacks

PHP Syntax - Learn Basic PHP - PHP Hello World Program

Hello Readers, Today TechAttacks will show you the basics of PHP.
PHP is a server side scripting language that, very often along with databases created with SQL, which can create dynamic webpages.
In other simple words we can say PHP script is executed on the server and the plain HTML result is sent back to the browser.

A PHP script can be placed anywhere in the document.
A PHP script starts with "" and ends with "?>"


The default file extension for PHP files is ".php".
A PHP file normally contains HTML tags and some PHP scripting code.
Below, we have an example of a simple PHP file, with a PHP script that uses a built-in PHP function "echo" to output the text "Hello World" on a web page:



  
    

My first PHP page


    
  
- PHP statements are terminated by semicolon (;). The closing tag of a block of PHP code also automatically implies a semicolon (so you dont need to have a semicolon terminating the last line of a PHP block).

- 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 editing the code.
- Comments are useful for:
-> To let others understand what you are doing - Comments let other programmers understand what you were doing in each step (if you work in a group)
-> To remind yourself 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
PHP supports three ways of commenting:


        // This is a single line comment

     # This is also a single line comment


     /*
     This is a multiple lines comment block
     that spans over more than
     one line
     */

  ?>

In PHP, all user-defined functions, classes, and keywords (e.g. if, else, while, echo, etc.) are not case-sensitive.
But all PHP variables are case-sensitive.
PHP uses "$" keyword to declare a variable, for declaring & assigning value to a variable we have a small example below.

  
    

            $a = "apple";   // Here $a is variable with value "apple" in it.

            $A = "APPLE";   // & $A is another variable(cause its case-sensitive) with value "APPLE" in it.
            echo $A;  //This will give output(print) "APPLE".

     ?>
  

- You can use any text editor to make / edit PHP Script.

Conclusion: In this post we got small Introduction to PHP Programming / Scripting, PHP Commenting, Declaring Variable in PHP & Assigning Value to Variables & Hope you guys enjoyed your first PHP "Hello World" Program / Script.
- We will surely continue to more PHP Programing Scripts soon, till then keep visiting.

No comments:

Post a Comment