What is PHP?
- PHP is a recursive acronym - 'Hypertext Preprocessor'. From rather humble beginnings as the “Personal Home Page” scripting language, PHP has found its way into almost every server, corporation, and dev shop in the world. On an average day, somewhere between 500,000 and 2 million coders do something in PHP.
- An Open Source, server-side, cross-platform, scripting language used to create dynamic web pages.
- Originally created by Rasmus Lerdorf in 1995 and has been in continuous development ever since.
- Has evolved to include a command line interface capability and can also be used in standalone graphical applications.
- Can be embedded into a regular HTML document. For example,
- <title>My first PHP Page</title>
- This is normal HTML code
- echo '<p>This line of HTML was generated by a PHP script embedded into an HTML document</p>';
- Back into normal HTML
- It allows developers to build logic into the creation of web page content and handle data returned from a web browser. PHP also contains a number of extensions that make it easy to interact with databases, extracting data to be displayed on a web page and storing information entered by a web site visitor back into the database.
- PHP consists of a scripting language and an interpreter. The scripts are embedded into the HTML documents that are served by the web server. The interpreter takes the form of a module that integrates into the web server, converting the scripts into commands the computer then executes to achieve the results defined in the script by the web developer.
-Significant websites are written in PHP including the user-facing portion of Facebook, Wikipedia (MediaWiki), Yahoo!, MyYearbook, Digg, Joomla, WordPress, YouTube, Drupal and Tagged.
How it works?
- To develop an understanding of how PHP works it is helpful to first explore what happens when a web page is served to a user's browser.
- As far as the web server is concerned the web browser understands the content of the web page file and knows how to interpret and render it so that it appears as the web designer intended.
- A web browser, however, knows absolutely nothing about any PHP script that may be embedded in an HTML document.
This is where the PHP pre-processing module comes in. The PHP module is, integrated into the web server. The module tells the web server that when a page is to be served which contains PHP script (identified by special markers) that it is to pass that script to the PHP pre-processing module and wait for the PHP module to send it some content to replace that script fragment. The PHP processing module understands PHP, executes the PHP script written by the web developer and, based on the script instructions, creates output that the browser will understand. The web server substitutes the content provided by the PHP pre-processor module in place of the PHP script in the web page and sends it to the browser where it is rendered for the user to view.
- A prime example of this involves displaying a web page which contains some data from a database table. Since the database esides on a server it makes sense for any script that needs to extract data from the database to be executed on the server, rather than waiting until it reaches the browser. It is for this kind of task that PHP is perfectly suited.
- It is also fast and efficient because the script is executed on the server it gets to take advantage of multi-processing, large scale memory and other such enterprise level hardware features.
- It is also fast and efficient (because the script is executed on the server it gets to take advantage of multi-processing, large scale memory and other such enterprise level hardware features.
- In addition to the advantages of being a server side scripting language PHP is easy to learn and use. The fact that PHP works seamlessly with HTML makes it accessible to a broad community of web designers.
- Perhaps one of the most significant advantages of PHP to some is the ease with which it interacts with the MySQL database to retrieve and store data.