Introduction to PHP
So you want to learn PHP? You may already know a web language like HTML and you want to move on to something more interactive, or you may have heard about PHP and are curious about it, or one of many other reasons. Whatever your reason(s) may be, PHP is a great language to learn!
This tutorial focuses on:
- What you should already know
- What is PHP?
- PHP file extensions
- What can be done with PHP?
What you should already know
Before beginning your studies of PHP, you should already have at least a basic understanding of:
- HTML/XHTML - PHP scripts are placed on webpages with HTML/XHTML tags and without knowing these tags, you will not know where and how to place PHP scripts on a webpage. Check out our HTML tutorials or XHTML tutorials if you are not yet familiar with these languages.
- A scripting language such as Javascript - PHP is an advanced scripting language. If you already know another scripting language such as Javascript, learning PHP will be easier. Learn Javascript at our Javascript tutorials section.
What is PHP?
PHP stands for Hypertext Preprocessor (it's a recursive acronym). PHP is a language used to develop interactive and dynamic content on the web and it is often used together with the Apache web server. It can also be used with Microsoft's IIS web server.
- PHP is a scripting language - Code written in PHP is not executed but interpreted by another program at runtime instead of being compiled by a computers processor. Other scripting languages include Javascript and VBScript.
- PHP is a web language - It is used to create content on webpages.
- PHP is a server-side language - Unlike some other web languages, PHP is server-side as opposed to client-side. If you try to view the source code of a web page, you will see that it may have been written in various language including HTML and Javascript. The source code you will be seeing however, is client-side code - the code of those languages that execute on the browser. If a webpage is written using PHP, you will not see the PHP source code used to create the page if you try to view the source code of the page. While PHP executes on the server, and not the browser, PHP files will be returned to the browser as plain HTML.
- PHP is an object-oriented language - In PHP you can define your own reusable data structures called objects as well as define their attributes (properties) and things they can do(methods). You can also create relationships between various objects and data structures.
- PHP is an open source language - PHP's source code (the source code used to create PHP) is freely available to the general public.
PHP file extensions
PHP files have an extension of .php, .php3, or .phtml. The .php extension is the one that is most often used.
What can be done with PHP?
- Get data from forms - You can get data from forms submitted by users. For example, you can have users submit their e-mail addresses to be added to a mailing list.
- Read and write cookies - A cookie is a small text file stored by a website on a users hard drive. With PHP, you can create cookies to store on a users hard drive and later read them. For example, you can store a users preference for the background color of a webpage in a cookie, and every time the user visits your website again you can read the cookie that stores this value and set the background color to the users preference accordingly.
- Read from and write to files - For example, you can create a guestbook on your website that is stored in a text file, and you can let users sign or view the guestbook.
- Detect the user's browser - For example, you can find out if a user is using Internet Explorer or Firefox.
- Communicate with databases - Read data stored in a database or write new data to a database. For example, you can store a users name and e-mail address in a database, and allow them to retrieve this information and view it or change it, and the change will be reflected in the database.
All this and more can be done with PHP!
