So far we have learnt basic information about what PHP is? And how you can configure PHP on your machine, now we will start learning PHP.
PHP is a scripting language, so the scripts which you create using PHP needs not to be compiled rather it’s interpreted directly on the go at run time.
Let’s start with the character set of PHP. PHP supports following set of characters.
All PHP scripts will be saved using the extension “.php” , like HTML all your files will be stored as plain text.
The coding of PHP can be done in the following different manners:
This is the normal style for coding. Here for this type all the PHP script should begin with and it should end with ?> , the beginning tells that whatever is written between these 2 tags is your PHP code.
<?php echo “hello world”; ?>
It is as same as traditional coding style except for the beginning of PHP code is replaced by Instead of , for using this format you need to change your php.ini file , search for short_open_tag=off and replace it with short_open_tag=on
<? echo “hello world”; ?>
For this type the first line of your code should be indicates the end of PHP script.
< script language=”php”> echo “hello world”; </script>
For this type the first line of code should be <% and %> should be written to end your script , for using this coding style again you need to set the configuration option in your php.ini file.
Let’s start with the simple PHP program. To get started first open any editor you want to use for writing your PHP code (Like Notepad, Dreamweaver, Notepad++ etc), write the following code in your editor
<?php echo “Hello Discuss Desk ”; ?>
Save this file into your root directory for PHP.
Note that it will be www in case of WAMP (WAMP>WWW) , htdocs in case of XAMPP (XAMPP>htdocs).
Create a folder in htdocs to store all your PHP programs, save the file with a unique name and with extension .php
For Ex. Variable name $NAME , $name & $NaMe all will have different meaning.
For Ex. $name=”Pratik” is as same as $name = “Pratik” , Here the space between the variable and its value will be ignored
<?php echo “Hello DiscussDesk”; echo “Lets Learn PHP” ?>
In above code as you can see we have not used ;( semicolon) for the last statement and its perfectly fine.
So to summarize we have learnt the basic structure of PHP and now you have the basic knowledge of writing PHP scripts.