Using the PHP Manual

While programming, have you ever needed a function to carry out a certain task, but you did not remember it? You knew it existed, and you possibly had used it before. Where could you have found it? By learning how to use the PHP manual to the fullest extent you will never experience this problem again.

The official PHP website (external link) has amazingly good online documentation. You can find practically any answer you will commonly come upon, although sometimes you might become confused over what a certain section means and simply ignore it, when it could hold vital information.

Finding What You Need

The first step is to find what you are searching for. When you first arrive on the PHP website there is a search box clearly displayed in the top right corner of the web page. You type what you want to search for in the first text box, and then use the adjacent drop-down box to indicate the type of search. The types of searches that you will use most often will be the "Function List" and "Online Documentation," because they are the most useful for quickly getting information.

For a simple example, we are going to search for a very common function, nl2br(). This function adds XHTML line breaks (<br />) before all new lines (\n) in a string. Assume that you have no prior knowledge of this function - you do not know its name or what it does. You are simply looking for a function that will add HTML line breaks automatically.

The first thing you could do is to search in the "function list" for a function with "line break" in its name. Upon doing this, you will be told that no such function exists within the documentation. This is because the function search only searches within the names of functions to find matches.

Finding no results in the function list, we can now move on to do a wider, broader search using the "online documentation" search type. This type of search basically does a Google site search of the PHP website. As you can see, from our results, the nl2br() function is the second in the list of results.

Navigating Around A Function Page

When you select the search result you are brought to its function page, which fully details the function. There are many sections to a PHP function document:

nl2br() Function Page

  1. Function Name
  2. Compatibility - This shows in which versions of PHP the particular function is present. In our nl2br() example you can see that the function is present in PHP 3, PHP 4, and PHP 5.
  3. Brief Description - For most functions there is a simple, brief description, usually less than a few lines long, telling you what the function does.
  4. Function Syntax - This shows the manner in which you should use the function. It shows the arguments that you must and can pass to the function, and what types of data they are required to be. In our example there is only one variable that is required, a string, which is referred to, helpfully, as "string."
  5. Description - This is where the function is further explained. There are also notes in this section that you should pay attention to. In this case it is the fact that since PHP 4.0.5 nl2br() will return the XHTML compliant <br /> and not the HTML <br>.
  6. Example(s) - In most function documents, there is usually at least one simple example of how the function is to be used. With more complex functions there may be up to five examples of its usage.
  7. Related Functions - If there are functions that are closely related to the current function you are reading, there will be links to them at the bottom of the document. For example, the fwrite() function has a reference to the fopen() function, which must be called in order for you to use fwrite(). This small section can be useful for quickly reading about an entire area of PHP, such as file manipulation.

The official PHP website is the most useful resource on the Internet for any PHP programmer, as long as they have learned how to properly use the manual. If used correctly, you will be able to learn new functions and read about ones that you have forgotten, thus helping you to program easier.