Monday, January 25, 2021
Home PHP PHP Lessons PHP Lesson 1 : Hello World

PHP Lesson 1 : Hello World

PHP Lesson 1 : Hello World : 

Hi Guys,

I am starting this series of tutorials in which i will be writing lessons about PHP and you will be learning PHP step by step. So as usual in all programming languages lets start with the Hello World” program. I am assuming that you have installed PHP on your system, and if not then for MS Windows please read this.

For writing PHP code, you can use Notepad and for more advance environment you can use some IDEs like Adobe Dreamweaver, Zend Studio and Eclipse. For more IDEs, please read this post from IBM.

Open your IDE, and write down the code below ( Please dont copy paste 🙂 )

<?php //PHP start tag

/* Print Hello World */

 echo "Hello World";

//PHP end tag
?>

Explanation : Now lets explore the above code line by line. Look at the line 1 and line 7. Every PHP file starts with PHP starting tag ( <?php ) and ends with a PHP end  tab ( ?> ) . The starting tag is always required and the ending tag can be ignored, but for best practice use end tag also at end of the file.

At line 1 after PHP start tag, you can see PHP comments. Comments are very important and it document your code. There are two types of comments, single line comments and multiple lines comments. At line 1 and line 7 you can see single line comments started with double slashes ( // ). Single line comments can be only with a single line and ends at the end of the that line. Multiple line comments are used at line 3. It starts with ( /* ) and ends with ( */ ), so these comments end where the ending */ us placed.

At line 5 the real operation is performed.

 echo "Hello World"; 

This line prints the text Hello World at your browser screen. echo output text or other data. You can also use it as followed

 echo("Hello World"); 

Please note that echo is not a PHP function, it is a language construct, so it is not required to use parentheses with echo.

echo is not the only way to output or print text in PHP. You can use print construct also as below

 print "Hello World"; 

After you type the above code, then save the file with name hello.php and save it your server. Open your browser and type the link like http:///www.yourserverlink.com/hello.php and you will see the text Hello World printed on browser screen. Now try some more texts other than hello world.

Our PHP Lesson 1 : Hello World lesson ends , and the next lesson is PHP Data Types and Variables .

- Advertisment -

Most Popular

Android Webview Tutorial With Example | How to Use Webview in Android

Android Webview Tutorial With Example Have you seen an Android app displaying Web content using Webview. This Android Webview Tutorial is about integrating Webview using Android Studio....

Student Registration Project in PHP

In this Student Registration Project we are providing a form in simple html to the student and that form sends the data to "student.php"...

Java GUI Calculator Source Code

Here we have a Java GUI Calculator Source Code for you in which a Java GUI calculator has been created using "swing" and "awt". The calculator has...

Numeric Array in PHP

Numeric arrays can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from zero....