This video shows you the basics of the PHP scripting language. Basically, you will learn starting with PHP language.
I use Visual Studio Code as my coding editor.
What is PHP?
So, what is PHP?
- PHP is a server-side scripting language, which means that it is executed on the server and not the client computer
- It is free and widely used language
- Used to build dynamic and interactive web applications
- Instructions are executed in sequence, starting from top and going downwards, line by line
- Not required to compile code (as with Java language for example). The code is executed by the server
- Must have a web server installed, to execute the code (we use Apache server that comes with XAMPP package). If you use shared hosting, make sure that your hosting provided has Apache server up and running
- Mostly used with HTML pages. When the server, receives the PHP request, it goes through the file and whenever it find PHP code, it executes it and prepares a response to return it to the client
PHP execution workflow
Lets see the execution flow, starting from the client.
- The client opens the web browser and makes the PHP request.
- The request is sent using a PHP file
- The server receives the file and processes it. If any data needs to be fetched, it contacts the database management system (in our case we use MySQL. Other example are PostrgreSQL, MSSQL ….) and fetches the required data
- When all PHP and/or database request is processed, a response is prepared (usually in the form of HTML file)
- The response is sent to the client
- The client browses the response file, through his web browser
Below is a simple PHP code line.
<?php echo "Hello there"; ?>
The “<?php” part, represents the PHP opening tag. This shows the web server that this is a PHP code and it needs to be executed.
The part “echo” is the string output statement.
The part “Hello there” is a simple string and it must be within single or double quotes.
The “;” (semicolon) must be used at the end of each code line. It marks the end of one code line. The server will return an error, if the semicolon is not written at the end of the line.
Finally, the “?>” is a closing PHP tag. It marks the end of the PHP code. Shows the web server that the PHP part to be executed, ends there.
As an example, we can use the “index.php” filename.
Always, when you name a file that has a PHP code in it, you must save it with the “.php” extension.
Each time the server receives a file with the “.php” extension, it looks for a PHP code to execute.
If, for example you use any other extension (like .html), the server will never look for PHP code in it, as it is configured to automatically skip all the files that don’t have “.php” extension. Even if you have PHP code (within the tags “<?php” and “?>”, saved in the .html file, the server won’t execute it, if the file is not name having the “.php” extension in the end.
PHP is widely used scripting language, usually used in the web development.
It is an easy to learn language and most of the time, all the programming beginners, start their programming journey with PHP.
Hopefully this tutorial was useful to you.
Thanks for reading this article.