When we talk about popular programming languages, usually at the top of the list is PHP, a favorite among developers and software engineers who use frameworks based on this language to build modern and multifunctional web pages and applications.
PHP is one of the most popular scripting languages and works on the server side. Its acronym means “Hypertext Preprocessor” in Spanish and it is embedded in HTML. It allows: creating personalized web content, sending and receiving cookies, evaluating form data sent from a browser, etc.
In addition to its features, it has integration with several popular databases like Postgre SQL, Oracle, Sybase, SQL, and MySQL. It also handles forms, saves data to files, and collects data from files.
A PHP script can be placed anywhere in a document. This script starts with <?php and ends with ?>. We present an example:
<?php // PHP code goes here ?>
The default extension of PHP files is: .php. A PHP file usually contains HTML tags and some PHP script code.
The following is an example of a simple PHP file, with a script that uses a built-in echo function to output the text "Hello world!" On a website:
<!DOCTYPEhtml> <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html>
In the PHP language, keywords such as else, echo, if, classes, functions, and functions that define a user are not case sensitive. As an example we show the following line of code, where the word echo is written in different ways and all are valid:
<!DOCTYPEhtml> <html> <body> <?php ECHO "Hello World!<br>"; echo "Hello World!<br>"; echo "Hello World!<br>"; ?> </body> </html>
But surprisingly, all variable names are case-sensitive. In the example below, only the first declaration will display the value of the $color variable. This is because $color, $COLOR, and $coLOR are treated as three different variables:
<!DOCTYPEhtml> <html> <body> <?php $color = "red"; echo "My car is " . $color . "<br>"; echo "My house is " . $COLOR . "<br>"; echo "My boat is " . $COLOR . "<br>"; ?> </body> </html>
Among the main differences between both programming languages are: