Introduction to PHP

What is PHP?

PHP stands for PHP: HTML Preprocessor. It is a general-purpose scripting language designed for web development. PHP is also commonly embedded within HTML and can be written within and around your HTML code. Like JavaScript, PHP is also a scripting language, meaning that it does not need to be compiled and it will only do something after an event occurs - for example, a user visits your site.

PHP is a server-side language. This means that all PHP code is interpreted and run on the webserver and not in the browser or client.

PHP is cross-platform, meaning that it can be used on web servers running on Unix, Windows, macOS, and other operating systems. It can also be moved from one platform to another with few or no modifications.

What PHP is Not?

PHP is not a client-side technology. You cannot run a PHP file directly in the browser without the addition of a webserver. Unlike JavaScript, which IS a client-side language, PHP cannot create new browser windows, make a pop-up dialog box, or directly respond to user action like scrolling through a page or typing in a text box. PHP can be used to create HTML or JavaScript, but once that information has been received by the browser, PHP can no longer make any changes to the page or content.

Why use PHP?

With PHP, you can create more exciting and dynamic pages than would be possible with HTML alone, like interacting with databases and files, handling emails, and creating sophisticated templates. And because PHP is an HTML preprocessor, once PHP has been interpreted the webserver will only send HTML, CSS, and JavaScript to the browser.

Creating enticing and lasting websites cannot be done with HTML alone. Server-side technologies, like PHP, allow developers to create web applications that are dynamically generated that are often database-driven and can be updated and maintained easier and faster than static HTML pages.

There are other server-side technologies other than PHP, such as ASP.net, Java, Ruby, and Node.js. While these alternatives are very capable there are several reasons to learn PHP over these other languages:

  • PHP is easier to learn and use
  • PHP was written specifically for web page creation
  • PHP is free and cross-platform
  • PHP is the most popular tool for developing dynamic websites

How does PHP work?

PHP files reside on a web server that will serve up web pages to a browser. When you go to a website, your browser is directed to the web server that holds that website files. If the server sees that a PHP file was requested (PHP files end with .php instead of .html), then the server will request the PHP server to read the PHP code and process it according to its scripted directions. When the PHP server completes its interpretation of the PHP file, it sends back the web page data in the form of HTML. In other words, PHP creates HTML pages on the fly and the server sends that HTML code, and only the HTML code, to the browser.

A diagram of the PHP Process