Introduction to Php
Introduction to PHP
PHP is a server-side scripting language designed to be used for web purposes. PHP started out as a small open-source project that evolved as more and more people found out how useful it is. It is so popular because it’s very simple to learn, code and deploy on the server.
Software Requirements
To run PHP code, we need the following software on a local machine:
- Browser
- Web Server(e.g., Apache)
- PHP (Interpreter)
- MySQL Databases (optional)
We can separately install Web Server, PHP interpreter, and MySQL databases.
Hardware Requirements
We just need a laptop or desktop computer. PHP 5.5+ requires a computer with at least Windows 2008. The computer with a Pentium IV processor, RAM 2GB, hard disk 256 GB is more than enough.
Object-Oriented Programming with Server Side Scripting
Object-Oriented is an approach to software development that models applications around real-world objects such as employees, cars, etc.
A class defines the properties and methods whereas an object is an instance of a class.
There are three major principles of OOP:
- Encapsulation: It is concerned with hiding the implementation details and only exposing the methods. It is used to reduce software development complexity.
- Inheritance: It is concerned with the relationship between classes. The main purpose of inheritance is re-usability.
- Polymorphism: It is concerned where the same functions can be used for a different purpose. E.g., function name will remain the same but it takes different number of arguments and can do different tasks.
Basic PHP Syntax
A PHP script is executed on the server, and the plain HTML result is sent back to the browser. A PHP can be placed anywhere in the document.
The default file extension for PHP files is “.php”
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>