Tuesday, July 19, 2016

Introduction to PHP Tutorial

What is PHP?

PHP was developed by Rasmus Lerdorf in 1994.

PHP is a recursive acronym for PHP: Hypertext Preprocessor. It is widely used open source scripting language embedded into HTML that is suitable in developing dynamic web pages. It is compatible with most DBMS such as MySQL, Oracle, Sybase, etc.

PHP is a server side scripting language. Therefore, php scripts runs/executed on the server. You will be needing a software such as WAMP (Windows, Apache, MySQL, PHP), XAMPP, LAMP for Linux operating System and MAMP for Mac OS. If you are going to upload it online, you will be needing a server that runs apache, php, mysql  such as Apache or IIS.

You can download the latest version of WAMP Server on their official website. Or if you wish to use XAMPP which what I prefer, you can download it here.

Install it in your windows pc or if your using Linux then you install LAMP. To run your PHP, you need to look for XAMPP control panel. Make sure to install it first. Next, a form will display that looks like in the image below. Click on the start button that corresponds to Apache.

How PHP really works using this software? Let's take the following code as an example.

<!DOCTYPE html>
  <title>Simple PHP Script</title>
  <?php echo "Hello World!";?>

Your php script starts with the PHP start tag <?php and ends with a php end tag ?>
The code is being executed on the server and generating an html code back to the users web browser. The users will see a running script but will not be able to see the underlying php script.

A sample visual for you to easily understand. This is your php script on the server.

This is how the code looks like after passing the server.

And this is how it looks like in the user's browser.

Where to save your files in XAMPP?

You can create your php script in any text editor. In my case, I used the Notepad++. Save your file with a php file extension. Example sample.php and save it to the directory 


For the WAMP, 


 Or you can visit one of my post related to XAMPP tutorial.

Displaying Output

PHP uses the echo() statement to display outputs like in the above example. Enclosed string with double quotation to display string values.

Common uses of PHP

  1. Perform system functions: create, open, read from, write to, and close files on your system; execute system commands; create directories; and modify permissions. 
  2. Gather data from forms: save the data to a file, send data via e-mail, and return manipulated data to the user. 
  3. Access databases and generate content on the fly, or create a Web interface for adding, deleting, and modifying elements within your database. 
  4. Set cookies and access cookie variables. 
  5. Start sessions and use session variables and objects. 
  6. Restrict access to sections of your Web site. 
  7. Create images on the fly.
  8. Encrypt data.

PHP Comments

Comments are used to document your codes in php or to test some part of the code for debugging purposes. Comments are being ignored by the parsing engine and are not executed. 

There are three (3) type of comments, //  and # for single line comment, and /* */ for multi line comment.

//This is a comment.
#This is a comment.
This is a multi 
line comment.

PHP Variables

PHP variables are used to store values such as string, numbers and arrays. All variables in php starts with a $ sign. The following are the naming conventions in creating variables in php.

1. It must start with a letter or an underscore ( _ ). 
Example: $first, $_last, $var1
2. It can only contain alphanumeric characters and underscore. (a-z, A-Z, 0-9, _).
Example: $num1, $first_name, $_num1
3. It should not contain spaces. If it is more than one (1) word, separate it with an ( _underscore such as $first_name or with capitalization $firstName.

4. It should be descriptive yet short.

5. It is case sensitive. Meaning, $a is not equal with $A. ($a<>$A)

Declaring Variables

  $text="Hello World!";
  echo $text;

The script above will display Hello World! in your browser. If values are numbers, do not enclosed it with double quotation ("").

  echo $num;
  echo $pie;

Code Cohabitation

Code cohabitation exist when you want to put html tags inside your php script. Since you cannot directly put html tags in php, you need to do echo the html tag and put it inside the double quotation ("") like in the below example.

  echo $num;
  echo "<br>";
  echo $pie;

  $text="Hello World!";
  echo "<h1>$text</h1>";

Note: Use double quotation "" if you want to display the actual value of variables. Use single '' quote to display the literal name of the variable.

String Concatenation

There will be cases wherein you need to combine two or more string values together. To achieved this, you need to use the concatenation operator which is the period ( . )


  echo $text1." ".$text2;
The purpose of the " " is to put a space in between Hello World. Its like Hello + space + World.

Watch out for more articles related to programming and even systems administration. Please do hit the like button on the right sidebar of this page.

Introduction to PHP Tutorial


  1. Thanks for your informative post!!! After completing my graduation, I am confused whether to choose web design as my career. Your article helped me to make a right choice. PHP Training in Chennai

  2. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.

    java training in bangalore

  3. Very useful article.Some valuable tips on how to open URL in Google Chrome Help browser.Waiting for new updates.
    BE/B.Tech Project Center in Chennai | BE/B.Tech Project Center in Velachery

  4. Awesome Post! I like writing style, how you describing the topics throughout the post. I hope many web reader will keep reading your post at the end, Thanks for sharing your view.

    white label website builder


  5. Thank you so much for sharing this worth able content with us. The concept taken here will be useful for my future programs and i will surely implement them in my study. Keep blogging article like this.
    Php course in chennai

  6. Thanks for sharing this information and keep updating us. This information is very useful to me.Excellent Multimedia Summer Courses in Porur | Best Vacation Classes in Chennai

  7. Pretty article! I found some useful information in your blog, it was awesome to read.
    Adobe Photoshop Vacation Classes in Chennai | Best Technical Boot Camp in Chennai


  8. Great blog. You put Good stuff. All the topics were explained briefly. So quickly understand for me. I am waiting for your next fantastic blog. Thanks for sharing. Any course related details learn...
    Php course in chennai

  9. Hey, Wow Provided Post will be Very much Informative to the People Who Visit this Site. Good Work! Thank You for Sharing.
    Joomla training in chennai

  10. Nice and informative article.Thanks for sharing such nice article, keep on updating.

    Python Training in Chennai
    Python Training

  11. Nice and interesting article about "Introduction to PHP Tutorial".
    Data Science Training in Chennai

  12. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
    Good discussion. Thank you.
    Six Sigma Training in Abu Dhabi
    Six Sigma Training in Dammam
    Six Sigma Training in Riyadh

  13. Online casino BGAOC big winnings and lots of lucky games are waiting for you. all slot machine games successful do not wait, make your luck smile to you.

  14. Я бы рекомендовал использовать профиль для светодиодных лент это нужно для того что бы лента дольше служила.