PHP Logo

Getting All Permutations Of An Array In PHP

29th February 2008 - 3 minutes read time

Here are two ways in which you can figure out all of the different permutations of an array.

The first is using a recursive algorithm. This nibbles apart the array and sticks it back together again, eventually resulting in all of the different permutations available.

Read the full article

Create A Simple Flash Presentation

28th February 2008 - 4 minutes read time

One common thing that can be done with Flash is to create presentations. These presentations can then be exported to a swf file and viewed by just about everybody.

To make a presentation create a new flash document and create a new layer. This layer will be used to keep the next and previous buttons in a consistent place.

On the first frame add the following code to stop the animation running at the first frame.


Next, create a button that you can use for moving forward and backward through the presentation. This can be done by drawing an object on the stage, right clicking on it and selecting Convert to Symbol.... You can then add these buttons to the stage and create events for them.

For the previous button a function exists in ActionScript called prevFrame(). So all you need to do is attach that function call to the release event (ie. after a user has clicked on it) on that button.

Read the full article

Apache HTTP Logo

Apache Bench Tool

25th February 2008 - 5 minutes read time

The Apache Bench tool can be found in the bin directory of any standard instillation of the Apache HTTP server. It can be used to test the response times of any web server you want and can be useful if you want to stress test a mission critical server before it goes live.

To use the tool open a command prompt (or terminal), navigate the Apache bin folder and find the program ab, this is the Apache Bench tool. The simplest form of running the tool is to use a single URL. However, you must enter a full file name or the tool will give you an invalid URL error.


This gives the following output.

Read the full article

Apache HTTP Logo

Avoiding URL Canonicalisation With mod_rewrite And Apache

22nd February 2008 - 3 minutes read time

URL canonicalisation is where you have a website with different URLs outputting the same content. When search engine spiders see all this content that is the same they can get confused as to what page to display in search engine result pages. The following URLs, although they are different, actually produce the same content.

The way to solve this issue is to redirect any requests to a single page using mod_rewrite. Add a .htaccess file to your root directory and include the following line to turn on the engine.

RewriteEngine On

The following rule will redirect the www page to the non-www page.

Read the full article

WordPress Logo

Creating A Widget Proof Wordpress Theme

21st February 2008 - 5 minutes read time

Wordpress widgets are a way to customise the sidebar of your blog very easily and where included with the default Wordpress instillation from version 2.2 onwards. With a widgetised theme all you need to do to change the menu system on your blog is drag and drop features and edit some simple parameters like heading.

To include widgets on your blog you need a widget ready Wordpress theme. However, this isn't as easy as it sounds because only a small section of themes are widget enabled.

To make a widget enabled theme you can use any existing theme and just a few lines of code. First off, find the file called sidebar.php in your Wordpress theme directory. You might not have this file, but you are looking for the section of code that displays the navigation menu.

Read the full article

PHP Logo

Display Wordpress Feeds On Your Site With SimplePie

20th February 2008 - 2 minutes read time

You can display your latest Wordpress posts anywhere on your site by using an RSS reader called SimplePie and a few lines of code. SimplePie is a fast and efficient RSS reader, and it will also cache feeds to reduce the amount of processing time taken.

Download simple pie from the website and upload the file to your web server. Next include the following section of code anywhere on your site that you want to display the latest post on.

Read the full article

PHP Logo

Force File Download With PHP

19th February 2008 - 4 minutes read time

When you supply files that web browsers can open they are usually opened inside the browser, rather than being downloaded. This can be annoying, especially where PDF documents are involved. You could supply the files in a compressed format in order to force users to download them, but this is also annoying as the user then has to uncompress the file.

You can force the web browser to supply the file as a download by using the header() function in PHP. The following little bit of code will take any filename and supply it as a download.

$file = $_GET['file'];
header('Content-type: octet/stream');
header('Content-disposition: attachment; filename='.$file.';');
header('Content-Length: '.filesize($file));

All you have to do is link to this script with the argument being the file name you want your users to be able to download.

Read the full article

JavaScript Logo

JavaScript Simple Loop Optimisation

18th February 2008 - 3 minutes read time

When writing JavaScript applications I normally write for loops like this.

for (var i = 0; i < elements.length; ++i) {
  // loop...

There isn't anything wrong with this, but it is not an efficient way of doing things. All it takes is a little knowledge of what the for loop does every time it runs. The loop can be split into three sections like this.

Read the full article

PHP Logo

Passing Values By Reference In PHP

16th February 2008 - 3 minutes read time

For most functions it is normal for have the function return the output of a calculation. With PHP it is also possible to pass values to the function by reference. A better way of saying this is rather than pass the value of the variable you pass a pointer to the variable itself. When you do this anything that you do to the variable inside the function is also done outside, so if you interact with the variable again it will contain a different value.

The ampersand (&) character is used in the parameters of the function to stipulate that a parameter will be passed by reference.

Here is an example of this at work.

Read the full article

PHP Logo

Recursive Directory Listing With PHP

15th February 2008 - 2 minutes read time

Use the following function to list the contents of one or more nested directories.

function recursive_directory($dirname,$maxdepth=10, $depth=0){
 if ($depth >= $maxdepth) {
  return false;
 $subdirectories = array();
 $files = array();
 if (is_dir($dirname) && is_readable($dirname)) {
  $d = dir($dirname);
  while (false !== ($f = $d->read())) {
   $file = $d->path.'/'.$f;
   // skip . and ..
   if (('.'==$f) || ('..'==$f)) {
   if (is_dir($dirname.'/'.$f)) {
   } else {
  foreach ($subdirectories as $subdirectory) {
    $files = array_merge($files, recursive_directory($subdirectory, $maxdepth, $depth+1));
 return $files;

Use this in the following way.

Read the full article