PHP Basic Syntax

You must create a PHP file (.php) to execute PHP code otherwise, it'll not work. PHP code start with <?php tag and close with ?> tag. And every line complete with a semicolon (; ). Ok now create a php file and open your file in notepad or other IDE (editor) and write down below code

<?php
echo "Hello World! This is my first PHP project";
?>

Now save you page name as hello.php into your local server's htdocs (XAMPP) or www (WAMP) folder. Now open your browser you will get output like this.


You can also use short tags to write PHP like 

<?= "Hello World! This is my first PHP project";?>
or,

<? "Hello World! This is my first PHP project";?>

or,

<script language="php">

echo "Hello World! This is my first PHP project";

</script>
If you use short tag then you have to configure it into php.ini and enable short_open_tag.
The first way is best for write PHP code and it use most developers.
You can also write PHP code using print . example

<?php
print ("Hello world!");
?>
It'll execute the same result like as echo but echo is better than print.



Did you like this article? it will be appreciated if you share a coffee or burger with the author

Sent $5 to the author
Sent $10 to the author

Need Assistance?

I'm Sajjad Hossain, working on web application development since 2012. Do you need assistance on your project? or are you stuck with problems? I am available to help you.
If you want to contact with me ping me at -

WhatsApp
Skype


We use cookies on our website. To find out more about how and why they are used or opt-out, please read our Cookie Policy. By choosing "I Accept", you consent to our use of cookies. Cookie Policy
Top