Introduction to PHP
PHP started out as a small open source project that evolved as more and more people found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.
- PHP is an acronym that stands for “PHP: Hypertext Preprocessor” in a recursive manner.
- PHP is a server-side scripting language that is seamlessly integrated within HTML. Its primary purpose is to effectively handle dynamic content, databases, session tracking, and even construct comprehensive e-commerce websites.
- The software is seamlessly integrated with several widely used databases, such as MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.
- PHP demonstrates impressive speed and efficiency in its execution, particularly when compiled as an Apache module on the Unix platform. The MySQL server, once initiated, efficiently processes even the most intricate queries containing extensive result sets within an exceptionally short period of time.
- PHP has the capability to support a significant number of major protocols, including POP3, IMAP, and LDAP. The introduction of PHP4 brought about the inclusion of support for Java and distributed object architectures, namely COM and CORBA, thereby enabling the possibility of n-tier development for the first time.
Common uses of PHP
- PHP is capable of executing system operations, such as creating, opening, reading, writing, and closing files on a system.
- Additionally, PHP has the ability to manage forms, enabling the collection of data from files, saving data to a file, sending data through email, and returning data to the user.
- Furthermore, PHP allows for the manipulation of elements within a database, including the addition, deletion, and modification of said elements.
- Moreover, PHP facilitates the access and setting of cookie variables.
- By utilizing PHP, it is possible to impose restrictions on user access to specific pages of a website.
- Lastly, PHP possesses the capability to encrypt data.
Basic Syntax
In order to gain familiarity with PHP, it is advisable to commence with uncomplicated PHP scripts. Given that the “Hello, World!” demonstration is PHP Basic syntax, our initial task will involve creating a simple “Hello, World!” script.
As previously stated, PHP is integrated within HTML. Consequently, within your customary HTML (or advanced XHTML) code, you will incorporate PHP statements such as the following −
<html>
<head>
<title>Hello World</title>
</head>
<body>
<?php echo "Hello, World!";?>
</body>
</html>
The above code will produce the following result:
Hello, World!
Examining carefully HTML output of the above example, it becomes apparent that the PHP code is absent from the file which the server sent to the Web browser. The PHP code which is present in the file is processed and stripped away by the server. It only displays the HTML output.
PHP codes can be written in three ways:
<?php PHP code goes here ?>
<? PHP code goes here ?>
<script language = "php"> PHP code goes here </script>
One of the most frequently utilized tags is the <?php … ?> tag, which we shall also implement in our tutorial.