PHP syntax and write a hello world program

Lets know about PHP syntax and write a hello world program

Hello friends, today we will know about PHP syntax & create a hello world program. In the previous post, we had install PHP setup and code editor if you have not installed these setups then you can check our previous post by clicking here and install PHP setup and code editor.

So let’s begin today’s journey:

PHP Syntax

Write PHP code always in opening PHP tag (<?php) and closing PHP tag(?>).

<?php 'here will be our php code'  ?>

PHP variables are declared by using a dollar symbol($), as we know how to declare a variable so let us create a variable

<?php $myvariablename  ?>

and to end the PHP statement always use a semi-colon(;) because this let us write a new statement in PHP, so complete example of a variable declaration is given below:

<?php $myvariablename = 'PHP Glossary' ; ?>

and save its program fill in PHP setup if you have installed xampp then go in xampp/htdocs/yourfile.php. if you have installed wamp then go in wamp/www/yourfile.php

“Hello World” Program

  1. Open your code editor
  2. Create a new file, save this file in  xampp/htdocs/hello.php location
  3. Just copy, paste below code in this file & save again
<?php 
   $message = 'Hello World';
   echo $message; 
?>
  1. Start your PHP server if it is not started
  2. Now open the browser and type there localhost/hello.php

The output will be there “Hello World”.

PHP is a case sensitive language Yes or No?

Following are Case sensitive in PHP

  1. Variables name
  2. Class properties
  3. Class constants
  4. Constants
  5. Array keys

Following are Case insensitive in PHP

  1. Functions name
  2. Class constructors
  3. Class methods
  4. Keywords and constructs

PHP ignores whitespace.

In blank/whitespace automatically ignored, suppose that we have created a variable and hit five tab buttons and after then we have ended the statement with the semi-colon(;) and when we execute this code it will produce the same output like as normal code.


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *