PHP is a server side scripting language. It was created by Rasmus Lerdorf in 1994. It is one of the popular scripting language widely used to access data from server.
PHP Current Version
The current version of PHP is 7.4.3
Why Should we learn PHP?
PHP is free. Easy to learn. And most importantly, most of the hosting service providers provide PHP as default scripting language. Those developers who want to work as freelancers, most of the client are going to prefer their website at a very low cost. So PHP would be best option. Often most professionals claim because PHP is free, so there are tons of security loop holes in it. But this is not true. There are loop holes in every scripting language. It is the duty and responsibility of the developer to understand the security leaks and work accordingly.
- HTML codes are easily embedded
- Plenty tutorials, training available online
- Any one can learn in short span of time
- Plenty predefined functions such as in_array, explode, strpos function etc. eases the workflow.
- Handles server side queries easily.
- Provides sufficient server side information such as user agent info, file name reading etc.
Note: For practice purpose, download XAMPP and install it in your computer system.
How to create a PHP file?
Open a blank document, save the file with “.php” extension. The file name should not contain any space.
Type the below code.
<?php echo “Hello Gyanol”; ?>
Then save the file with .php extension. Open the file with any browser. And the browser prints the message.
The php code begins with “<?php” and ends with “?>”. If you are aware of HTML, most of the html markup tags has opening tag and closing tag. E.g. <b></b>, <h1></h1>. Same way, PHP has opening php tag and closing php tag. In between these two tags we write required PHP codes.
“echo” is a function that is used to print on to the browser. We pass desired information that we want to print. Here the information is “Hello Gyanol” and it is a string so we keep it in between double inverted quotes. Unlike java, .net, in PHP, we can use single quote to define a single variable. In java, .net etc. single quote is used to define single character. But this is not the case in PHP scripting. We can use single quote or double quote to define single character as well as string.
Alike any programming language, each statement in php script ends with a semicolon.
We can embed html codes in php script. E.g. lets print the Hello Gyanol text in bold.
<?php echo “<b>Hello Gyanol</b>”; ?>
Save it. And run it. It prints “Hello Gyanol” in bold.
Lets print five different fruit names.
<?php echo “Orange”; ?>
<?php echo “Grape”; ?>
<?php echo “Apple”; ?>
<?php echo “Banana”; ?>
<?php echo “Pine Apple”; ?>
If we save it and run it. We notice. It printed all the names in a single line. If we want to print the names one below another. Then we can include break tag (<br/>) to break the line.
<?php echo “Orange<br/>”; ?>
<?php echo “Grape<br/>”; ?>
<?php echo “Apple<br/>”; ?>
<?php echo “Banana<br/>”; ?>
<?php echo “Pine Apple<br/>”; ?>
If we save it and run it. It will print fruit name one below the other.
The above line of php code can also be written.
echo “Pine Apple<br/>”;
We can put multiple php statements in between opening php tag and closing php tag.