Introduction To PHP Programming For Beginners

PHP Logo
PHP is a web programming language on the server side that very popular. PHP is widely used by programmers to build a web-based application. PHP is also popular among the hosting provider where PHP is always included in the package of facilities provided by the web hosting service providers. Some Content Management System (CMS) which is quite popular among webmasters and bloggers such as Wordpress and Joomla! developed using PHP programming language. Currently, has been developed various PHP frameworks such as CodeIgniter, Laravel, Yii Framework that allows web programmers to do the coding neater and shorter with maximum results. At this time, PHP still relevant to be learned for beginners who want to engage in web programming.

Before practicing coding, we must make sure that the computer has installed the web server, because PHP is a programming language that integrates with the web server. If your computer is not already installed web server, you can read my tutorial about XAMPP installation. After you ensure that the computer has installed the Apache web server, now we need to prepare for PHP Editor. PHP Editor is a tool that will be used for typing the PHP code and manage the project. To start this tutorial I use Notepad++, or you can read a previous article about PHP Editor so that you may know the things that need to be considered to choose editor for web programming.

Now we will try to practice PHP starts from a simple script. Previously we need to know document root location of web server, which this directory will be used to store PHP files we have created so that web server can find our PHP files. For example, the location of the web server's document root on my computer at C:\xampp\htdocs, then I should be store PHP files in this location. To find your document root location of your Apache, you can read article about Apache Document Root.

Begin to write simple script of PHP Language

Writing PHP script always starts with <?php and ends with ?>. Now you try to practice by writing the following script in a text editor.
<?php
  echo "This text is sent using PHP.";
?>
Save script above with the extension .php and place at Apache Document Root location. I store that .php file as practice1.php on C:\xampp\htdocs as Document Root location on my local server. After that, open your web browser then type "http://localhost/practice1.php" at address bar of your web browser. You will get the result on your web browser like below:

Result on web browser of sending text using PHP

Now, look the page source by right click on web browser page then select View Page Source. On view source window we just get the a text "This text is sent using PHP.". It means that the code that represent PHP language such as open tag (<?php), closing tag (?>) and echo that function to sending string to web browser was processed on server side, while string that appear on web browser was an output of PHP script that has been processed by web server.

Sending HTML Document To Web Browser Using PHP

After practice the basic of writing simple PHP code, i will continuing to the next practice about create HTML document using PHP that will displayed on web browser. Before you step to this practice you should understand about how to write HTML code to produce an HTML document. In this practice, I will give you an example of simple HTML document that written and embeded on PHP script. Consider the following script :
<?php
echo "<!DOCTYPE html>";
echo "<html>";
echo "<head>";
echo "<title>Create HTML Document using PHP</title>";
echo "</head>";
echo "<body>";
echo "<h1>Content Titles is placed here between h1 tag.</h1>";
echo "<p>Content of this page are placed here.</p>";
echo "</body>";
echo "</html>";
?>
After typing those script, save with filename practice2.php and placed on document root location of your local server. Then run the file by accessing http://localhost/practice2.php on your web browser, you will get output like below:

Output of HTML Document on web browser that created using PHP

If you look the page source, you just get the html code because PHP has been processed on the server side. To see the page source, right click on main window of your web browser then select View Page Source. You will get HTML code like image below:

The Source of HTML Document

This article only as an introduction to the PHP programming language, hopefully this article can be helpful for beginners in learning PHP programming.