PHP is a popular general-purpose scripting language that is especially suited to web development.
Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.
1.What do I need?
In this tutorial we assume that your server has activated support for PHP and that all files ending in .php are handled by PHP. On most servers, this is the default extension for PHP files, but ask your server administrator to be sure. If your server supports PHP, then you do not need to do anything. Just create your .php files, put them in your web directory and the server will automatically parse them for you. There is no need to compile anything nor do you need to install any extra tools. Think of these PHP-enabled files as simple HTML files with a whole new family of magical tags that let you do all sorts of things.
2.Your first PHP-enabled page
Create a file named hello.php and put it in your web server’s root directory (DOCUMENT_ROOT) with the following content:
Example #1 Our first PHP script: helloworld.php
<?php echo '<p>Hello World</p>'; ?>
In the address bar of the browser, enter the URL of the web server to access the file and add “/hello.php” at the end. If local development, then the URL is generally http: //localhost/helloworld.php or http://127.0.0.1/helloworld.php, of course, depending on the web server settings. If all the settings are correct, then the file will be PHP par, the browser will output the following results:
<html> <head> <title>PHP Test</title> </head> <body> <p>Hello World</p> </body> </html>
The program is very simple, it just uses the PHP echo statement to show Hello World. Users will not be satisfied with this. Please note that the file does not need to be executed or specified in any way. The server will find the file and provide it to PHP for explanation because the server has been configured to automatically pass a file with a “.php” extension to PHP because it uses the “.php” extension. An ordinary HTML file, plus a few special tags, you can do a lot of very interesting things!