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.
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 web language - It is used to create content on webpages.
- 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!