You may be wondering why you should choose PHP over other languages such as Perl or even why you should learn a scripting language at all. Learning a scripting language, or even understanding one, can open up huge new possibilities for your website. Although you can download pre-made scripts from sites like Hotscripts, these will often contain advertising for the author or will not do exactly what you want. With an understanding of a scripting language you can easily edit these scripts to do what you want, or even create your own scripts.
Using scripts on your website allows you to add many new 'interactive' features like feedback forms, guestbooks, message boards, blogs, counters and even more advanced features like portal systems, content management, advertising managers etc. With these sorts of things on your website you will find that it gives a more professional image. As well as this, anyone wanting to work in the site development industry will find that it is much easier to get a job if they know a scripting language.
* Reduce the time to create large websites.
* Allow creation of shopping carts for e-commerce websites.
* Reduce execution time of dynamic page.
Before starting this tutorial it is important that you have a basic understanding and experience in the following:
* HTML - Know the syntax and especially HTML Forms.
* CSS- Must know about CSS it works for formatting of page.
* Basic programming knowledge - This isn't required, but if you have any traditional programming experience it will make learning PHP a great deal easier.
Declaring First PHP Code
PHP scripts are always enclosed in between two PHP tags. A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document.
<?
//Bad practice
?>
<?php
//Best Practice
PHP Code In Here
php?>
The first PHP script you will be writing is very basic. All it will do is print out all the information about PHP on your server. Type the following code into your text editor:
<?php
phpinfo();
?>
If you write this code and execute it you can get information about server. It outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment, the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.
How to display a message on php page
<html>
<body>
<?php
echo "Hello World!";
?>
</body>
</html>
Save this code as display.php and run it you will an out on page. Make sure php statement always end with semicolon(;).
Hello World!
How to make comments in PHP
Two type of comment exist – one is single line comment (//This is a comment) and second is
is multiline or block of comment (/* This is a comment block */ )
<html>
<body>
<?php
//This is a comment
/*
This is
a comment
block
*/
?>
</body>
</html>