4th Tutorial How to Write PHP Hello World Code
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.
Now right lick on folder appeared in sublime side bar and click to add new file.
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:
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.
Congratulations you successfully created your fist project in PHP.
Source Code understanding:
this is opening tag for html to let the sever know to process as html.
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.
here we closed head tag
body tag opened here in body all data for website goes which appears to web browsers
– – — 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
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.