What Is PHP

written by: Paul Huston; article published: year 2006, month 08;


In: Categories » Computers and technology » PHP » What Is PHP

PHP is an interpreted language. It strongly resembles the C language. It also has some flavor of the Perl language. It is available for almost all platforms, including Linux, other versions of the Unix family, and Windows.

PHP enables you to generate Web pages on-the-fly. You do this by pulling data from databases or files, manipulating that data, and then sending that data to a Web browser.
Using PHP, you can update databases, create databases, and perform mathematical calculations (including complex trigonometric functions). You can also create and delete arbitrary files on your system, depending on the level of security at which you have PHP running. You can create Internet network connections and service those connections. It is theoretically possible to write a Web server using PHP. You are limited only by your imagination.

Languages are either interpreted or compiled. An interpreter is a program that reads the file containing the code to be executed, and immediately acts upon it. The code in the file is called source code. In general, the code is readable and understandable by a person.
A compiler is a program that reads the source code file and compiles the program into binary code that can be executed directly by the computer. This binary code can't be read and understood by most people.

How It Works

The Web server generally runs PHP when a user requests a Web page that contains PHP code. Typically, the Web server is configured to use the filename extension to determine whether to run PHP. For example, a Web server will look at a Web page, and if it ends in .htm or in .html, the Web server will not attempt to execute any PHP script. If the page ends in .php (or in .php3, depending on how you have configured the Web server), the Web server looks at the contents of the Web page.
When the Web page contains one of the following escape sequences, it will run PHP to interpret that part of the page:

  • <? "php code" ?>
  • <?php "php code" ?>
  • <% "php code" %> (Only available when the php.ini setting asp_tags is ON. OFF is the default setting.)
  • <script language="PHP"> "php code" </script>

The Web page that the user sees is a mixture of the standard HTML commands on the page and the output of the PHP interpreter.

HTML stands for Hypertext Markup Language, and is a widely available standard for text documents. The home page for HTML is http://www.w3.org/MarkUp/. Several versions of HTML are available. All recently produced browsers understand at least HTML version 1.1.
PHP can also be built to run as a standalone program executing a file containing PHP code. This allows you to run timed programs using cron, or long-running programs from the command line. Any output from PHP when run in this fashion goes to stdout.

You will often see references to stdout, stdin, and stderr when the behavior of programs is being described. Whenever a program is run under Linux, three standard channels for information are opened.
The stdin channel takes information from an input source and feeds it to the program. This is usually done from the keyboard. You can, by using pipes (the | symbol) or redirection (the symbol), feed the information from files.
The stdout channel takes information from the program and sends it out to a device. This device is usually the screen on a terminal window. You can use pipes or redirection to send this output to a file or another program's standard input.
The stderr channel is for error messages, and cannot be easily redirected to a file or another program. It is typically reserved for debugging during development, and for indicating very serious errors the program cannot handle. Many programs quit immediately upon sending a message out stderr.
For example, look for all index.html files on your computer in the Web server directory. One way to do this is to run the find command, looking for files that contain html, and screen for index as part of the filename. This can be accomplished with this command line:

[root@winbook /]# find /home/httpd/html -name "*.html" -print | grep index

What It Does for You

With its capability to execute complex instructions on data inserted into or retrieved from databases, PHP is an ideal format for creating interactive Web sites. It supports multiple databases, including mSQL, MySQL, Informix, and Oracle.
PHP allows you to quickly generate interactive Web pages. Because it is interpreted, you don't have to go through any extra steps to use your program. Changes can be made to your Web page and tested immediately.
This allows you to learn in a stepwise fashion. It is perfectly acceptable to test each line of code as you go, noting the effects of each change.
Because Linux, Apache, and PHP are free, and because MySQL is free on Linux for most uses, you can inexpensively set up a test machine. This enables you to duplicate your production environment and test changes. This is critical when modifying software because it allows you to make as many mistakes as you need to without affecting your customers.

Getting Online Help for PHP

Help for PHP is available at http://www.php.net. Online documentation along with FAQs and mailing lists is available at that site.

legal disclaimer

1) Our website is not responsible for the information contained by this article as well for any and all copyright infringements by authors and writers. E-articles is a free information resource. If you suspect this article for any copyright infringements, please read the Terms of service and contact us to investigate the problem.
2) The E-articles directory team is not responsible for inaccuracies, falsehoods, or any other types of misinformation this tutorial may contain and will not be liable for any loss or damage suffered by a user through the user's reliance on the information gained here. Please read the Terms of service

Useful tools and features

Translate this article to...    Send this article to you or to a friend

Link to this article from your page   
If you like this article (tutorial), please link to it from your web page using the information above. Linking to this page, this is the only way to help us improve our service, the same time providing your visitors with a way to improve their online experience.

related articles

1. PHP Frameworks
PHP is finally getting the attention that i deserves, yes I have always believed that PHP is one of those neglected languages, neglected because they are used in abundance but there isn't enough programs or as we call them frameworks to work on PHP. But that was until the release of PHP 5. After the release of PHP, there is a range of Frameworks available. Today we review and understand closely the various frameworks available for PHP. Some of the most popular frameworks for PHP are: ...

2. Common PHP Errors
In this tutorial, we are going to look at some of the common PHP errors that occur and how to solve them. Parse Errors A parse error occurs when the format of your PHP code is incorrect. For example, the following code: <?php for($i=1;$i<10;$i++){ $output = "Current Iteration: " . $i . "<br>" echo $output; } ?> will return an error similar to the following: Parse error: parse error, unexpected T_ECHO in c:\webserver\test2.php on lin...

3. PHP mail
In this article, we are going to look at some of the frequently asked questions regarding e-mail and PHP. We will begin by looking at a more fundamental issue: how to actually send an e-mail as HTML. How Do I Send an E-mail As HTML? As the PHP mail function defaults to sending plain text e-mails unless otherwise specified, a frequent question is how to send HTML e-mails using the mail function. The format for the mail function is as follows: mail($to, $subject, $message, $headers); ...

4. PHP Date and Time
In this tutorial, we look at commonly asked questions regarding the date function in PHP. How Do I Read the Date or Time from the Server? To read the date or time from the server, you need to use the PHP date function. You pass the date function a string, with special tokens in place of the date parameters you require. When the code is run, the tokens will be replaced with the date or time section that they represent. For example: <?php echo date("d/m/Y"); ?> outputs 11/02/2003 &...

5. PHP Random Password
In some applications, it can be useful to generate a random password, such as setting the user's initial password and then letting the user change it if he or she wishes. The function shown in the following code generates a password with a number of random characters, and you can set the length of the password when you call the function: <?php function randomPassword($length) { $possibleCharacters = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $characterLength = strlen($possibleCharac...

6. How to Install PHP into Apache
In this section, we look at how to install PHP into Apache. The first step is to download it from the PHP web site. There are other sources for PHP around the Web, but it is much easier to get it from the source. Downloading PHP PHP is available as a free download from the PHP web site, http://www.php.net/ downloads.php. The file that you need to download is at the top of the page, in the section labeled Complete Source Code. The current file at the time of this writing was for PHP 4.3....

7. Installing PHP with Apache on Windows
We try to install PHP into Apache so it can process PHP pages and static HTML pages. We assume that you have installed and tested Apache. Downloading PHP The first step is to download PHP, which is available from the PHP downloads page at http://www.php.net/downloads.php. Scroll down the downloads page until you find the section labeled Windows Binaries. The current version at the time of this writing is PHP 4.3.0, and the...