PHP Syntax : First PHP ScriptPritesh
After installing PHP on your system/server we need to write our first php program which can be executed on the server.Writing PHP script is very easy because you already know C Programming language. Many syntax in PHP are like c language. We are writing our first PHP script to print “Hello World” in the browser window.
First PHP Script :
<?php echo "Hello World"; ?>
Explanation of First PHP Script :
- PHP Script is simply written in notepad / notepad++.
- PHP Script starts with <?php and ends with ?>
- PHP Script can be written/placed anywhere in the document.
- PHP Script can be embedded in HTML document.
Shorthand Property :
We can also write PHP Script between <? and ?>.
<? echo "Hello World"; ?>
but still it is not the proper way to write/include PHP code. For maximum compatibility we cannot write above mentioned syntax.
About PHP File :
- Whenever we write any PHP file then we must save it using .php extension.
- PHP file normally contains dynamic PHP Script embedded and HTML tags.
- Each statement in PHP is terminated by semicolon. Semicolon is used to distinguish two code statements of PHP.
- In PHP we have two basic statements to print text on the webpage i.e echo and print.