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
- Open your code editor
- Create a new file, save this file in xampp/htdocs/hello.php location
- Just copy, paste below code in this file & save again
<?php $message = 'Hello World'; echo $message; ?>
- Start your PHP server if it is not started
- 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
- Variables name
- Class properties
- Class constants
- Constants
- Array keys
Following are Case insensitive in PHP
- Functions name
- Class constructors
- Class methods
- 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.