function

function

Writing Function Code To Be More Readable

Wednesday, October 1, 2008 - 09:30

Last month I started writing functions in a particular way, which has made my life as a programmer much easier on more than one occasion. No matter how many comments or verbose parameter names you put in you can end up writing code that you will get lost in. The reason is simple. Lets say you had a function that took in a couple of parameters.

Category: 

Hiding HTML In Command Line PHP

Tuesday, August 5, 2008 - 12:04

Printing out stuff with PHP is basically essential to any program, but problems can arise if you want to use the same script for command line scripting and web site scripting because of the need to print out HTML. The $_SERVER super global array contains a variable called SERVER_PROTOCOL, which contains the protocol that the client is using to access the script. If the client access through the web then the protocol will contain something like 'HTTP 1.1'. If the script is being run from the command line then this super global variable SERVER_PROTOCOL would exist.

Category: 

Tidy Up A URL With PHP

Monday, August 4, 2008 - 09:20

Lots of applications require a user to input a URL and lots of problems occur as a result. I was recently looking for something that would take a URL as an input and allow me to make sure that is was formatted properly. There wasn't anything that did this so I decided to write it myself.

Category: 

Overloading Functions In PHP

Wednesday, July 16, 2008 - 10:01

One thing that PHP doesn't allow is the creation of multiple functions with the same name. If you try this then PHP will give you a fatal error. Creating different functions with the same name is useful if you want to pass different parameters to a function that produces the same result. There are two ways around this problem.

The first is that you can pass the function an array of the items that you want. You can then use this array in the function to do whatever you want. For example.

Category: 

Loading Page Styles And JavaScript With JavaScript

Wednesday, July 2, 2008 - 09:50

One good technique when using JavaScript is to load a single JavaScript file and get this file to load any other JavaScript or CSS documents that are needed. This means that you can simplify the instillation of a script on a page by including a single file, which then loads everything else it needs. Here is how to accomplish such a task.

Category: