How to PHP Scripting- First PHP Script

In this guide, we are going to make first PHP script and output it on a web browser. Before you start, install Xampp webserver software on your computer. Check our guide to installing Xampp on your computer. Basically, a PHP file is a text file with the extension .php which consists of Text, HTML tags, PHP Scripts. This tutorial mainly includes 2 steps. 1.Write & save First PHP script. 2.

 

1.Write and save PHP Script.

In Notepad++, choose ‘Save as’ under “File” in the top menu.
Find the folder  “C:\xampp\htdocs” and create a folder. (Here we create a folder “php”)
Choose “All Files” in the “Save as type” box. This is very important – otherwise, you save it as a text document and not as a PHP file.
Now save your document as i.e. “hello.php” (the ending “.php” indicates that it is a PHP file).

we need to tell the server when the PHP will start and end. In PHP you use the tags <?php and ?> to mark the start and end for the PHP codes that the server must execute.

Add the following code to your PHP file and save it.

php code
	<html>
		<head>
			<title>PHP Test</title>
		</head>
		<body>
			<?php echo '<p>Hello World</p>'; ?> 
		</body>
	</html>

 

2.Output in the Web browser.

Open Xampp control panel, and start Apache and MySQL.

XAMPP Control panel

First PHP Script

 

Open your browser and navigate localhost/PHP/hello.php.

Preview

First PHP Script

 

when you look at the HTML code in the browser, You can’t see the PHP code anymore. The only server can read the PHP code. We used the string function echo to write a specified string to the client where the semicolon ends the command.

 

PHP vs ASP.

The table below compare PHP and ASP (Active Server Pages).

FEATUREPHPASP
Learning curveshortLonger than PHP
Web hostingSupported by almost all hosting serversNeeds dedicated server
Open sourceYesNo
Web services supportBuilt inUses the .NET framework
Integration with HTMLEasyFairly complex
MySQL supportNativeNeeds third party drivers
Easily extended by other languagesYesNo

Anwar Yakkiparamban

Anwar Yakkiparamban is the founder of Lauyou Learning. Prior to Lauyou learning, Anwar worked at ARD Engineering & Development, Qatar. He holds bachelor degree in Electronics and Communication Engineering from Govt. Engineering College Idukki.

You may also like...