PHP 101: An Introduction

PHP (Hypertext Preprocessor) is an Open Source and world most popular server-side scripting language.

According to Wikipedia, as of January 2013 PHP was installed on more than 240 million websites and 2.1 million of web servers.

Why choose PHP over others scripting language?

  • It is freely available because of "Open Source" nature.
  • It can easily be embedded with HTML and CSS that produce dynamic web pages.
  • If you are a C programmer then it is very easy to learn PHP because its syntax is similar to C.
  • It can be easily integrated with popular databases such oracle, MySQL, PostgreSQL, Sybase and Microsoft SQL server etc.
  • It supports a large number of protocols like IMAP, POP3 and LDAP.

Prerequisites

No prior knowledge of programming is required to learn PHP. But having some prior working experience with HTML and C makes the process much faster and easier.

PHP is a server side scripting language. All you need to do is configure the server to process PHP. If you want to a local environment for executing PHP scripts then WAMP, LAMP, MAMP are respectively recommended for Window, Linux and Mac operating system.

Writing PHP script

You do not need any special software to write PHP script. You just need a basic text editor that comes with your operating system which can be used write the script. "Notepad" in Window, "vi" in Linux and "TextEdit" in Mac are the famous text editors used by users.

Declaring PHP

PHP scripts are enclosed between PHP markup tags that are recognized by its parser. Three forms of declaring PHP is as follows:

<?php
    PHP script is here
?> 
<?
    Php script is here
?>
<script language="php">
	Php script is here
</script>

All of the above forms works in a same way, but <?php ?> is mostly used in real scenarios. Let's write our first program "Hello World" in PHP.

<html>
    <head>
      <title>Hello World</title>
    </head>
	<body>
	    <?php 
	        echo "Hello world";
	    ?>
	</body>
</html>

All you need to do is save the above program with hello.php and upload it in your web server. When we type hello.php in a browser it displays a message "Hello world" will be rendered into the browser.
This completes our first tutorial on PHP. Stay tuned for more. In the second part, we will learn about PHP variables.
Image courtesy: NightLionSecurity

Reply

%d bloggers like this: