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
?> 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.
<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.
Open your browser and navigate localhost/PHP/hello.php.
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).
|Learning curve||short||Longer than PHP|
|Web hosting||Supported by almost all hosting servers||Needs dedicated server|
|Web services support||Built in||Uses the .NET framework|
|Integration with HTML||Easy||Fairly complex|
|MySQL support||Native||Needs third party drivers|
|Easily extended by other languages||Yes||No|