Use the following function to list the contents of one or more nested directories.
The set_error_handler() function can be used in PHP to allow you to catch any run time errors and act accordingly. This function can take two parameters:
- Error Handler : This a string which is the name of the function that will be called if an error is encountered.
- Error Types (optional) : This is an optional parameter used to tell PHP on what error codes to act. This is the same error reporting setting.
The function that is defined in the function must have the following footprint as a minimum.
You can also get a lot more information out by using other parameters.
Appending arrays in PHP can be done with the array_merge() function. The array will take any number of arrays as arguments and will return a single array. Here is an example using just two arrays.
The following code loads the contents of a text file and randomly displays a line from it. You can use this to display a random quote on a page every time it loads.
The first thing to do is grab the mootools library from the site and link it in your web page. You can select different components with mootools, but if you grab the whole thing you can start to play with whatever you want. Put this line of code in the head section of your web page.
For this example I want the highlight to occur when the page has finished loading. So I use the window.addEvent function to add an action for the 'domready' event to the window object of the page.
The singleton design pattern is used to centralise an object in an application that is used to store changing variables that can then be accessed by other parts of the program. It allows only the single instantiation of an object, hence the name.
The main use of a singleton is to create an alternative to the use of global variables. Although global variables are useful they can lead to a major problem if you happen to assign two variables with the same name, PHP generates no errors and your program will start to act oddly. This might not be a problem in small programs, but in larger systems it is very easy to have global variable clashes.
The singleton pattern gets around this by using an single object that is accessible to any part of the program that wants it. If two classes are declared with the same name PHP throws an error so if another part of the program tries to use the same class name you will know about it.
Because it is possible to mask your user agent in Opera it is necessary to detect this browser first. There are actually two different ways to hide the user agent in Opera. The default user agent is as follows:
Opera/9.23 (Windows NT 5.1; U; en)
It is possible to identify Opera as either Firefox or Internet Explorer. In this case the version of Opera is appended to the end of the user agent string so it is still possible to detect if the user has Opera and act accordingly.
Identify as IE
Every time you accept any input from a use you should attempt to validate it. This is to stop users trying to break the site and also corrects silly mistakes that users might introduce to their input.
Before sending off an email to a new user congratulating them on signing up it is best to validate that email address. Here is function that does this.
To find duplicate values you need to use the MySQL COUNT() function and then pick out all of the counts that are greater than one.