4th Tutorial How to Write PHP Hello World Code

PHP tutorials for beginners

Your First PHP Hello World Code

How to write PHP hello world code in simple and easy way. We will learn PHP in a very simple way. Welcome to first project for web designing  using PHP we will create a simple hello world project here to understand PHP syntax.

Step-1 Run your XAMPP server

Step-2 Create a new folder named HelloWorld following through C drive  XAMPP folder in htdocs folder.

Htdocs is root folder for your all php and html projects in XAMPP sever

Step-3 Open your text editor to code your project

In text editor open the project folder HelloWorld and create and new file index.php

When we work with PHP its must use .php extension to let the server know that here is a PHP file which will be processed using PHP server.

Now you have a empty  index.php file in your project folder HelloWorld. We used filename index because its main file in our project when a user sends a request to sever for a specific URL then server always check for the index file first. You can consider index file as a home page.

 

 

I am using sublime text here please download Sumblime Text to proceed further for project

To add your project folder in sublime click to File menu and then click Open Foler.

fist hello world project in PHP
fist hello world project in PHP

Now right lick on folder appeared in sublime side bar and click to add new file.

fist hello world project in PHP
fist hello world project in PHP setting up interface

Then save this file as index.php now you are ready to write code for your project here.

Now type the code in your text editor as below:

READ  5th Tutorial Creating and using Variables in PHP
fist hello world project in PHP source code
fist hello world project in PHP source code

After typing the complete code save file using ctrl+S or click to File menu and click to save

Now open your browser and in address bar type localhost/helloworld and press enter.

You will see your project as below.

fist hello world project in PHP output
fist hello world project in PHP output

Congratulations you successfully created your fist project in PHP.

Source Code understanding:

<html>

this is opening tag for html to let the sever know to process as html.

<head>

this is head opening tag in html is also necessary in basic html structure.

<title>Hello World project in PHP</title>

here we opened and closed title tags title appears in browsers title. Remember to close every tag using / slash when you open it while working in html.

</head>

here we closed head tag

<body>

body tag opened here in body all data for website goes which appears to web browsers

<?php

– – — this is PHP start tag  PHP  tag opened here to let the server know from here data should be processed using PHP

echo "Hello World this is filst hello world using PHP";

— echo is used to print your data to browsers screen

?>

— we closed PHP tag here

</body>

body closed

</html>

and HTML final tag also closed here.

For next tutorial click here

Please make sure to practice again and again to get better understandings for PHP basic structure.

Thanks for visiting we will meet in next tutorial soon.

 

Want to read again later ?? Share to save in your social media.