Display Wordpress Feeds On Your Site With SimplePie

20th February 2008

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 simplepie.inc 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.

Force File Download With PHP

19th February 2008

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.

Passing Values By Reference In PHP

16th February 2008

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.

PHP Headers Already Sent Error

14th February 2008

Try running the following PHP script.

 

You will either see normal output or get the following error messages.

Custom Error Handling In PHP Using set_error_handler()

13th February 2008

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.

Append One Array To Another In PHP

12th February 2008

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.

PHP Random Quote Generator

11th February 2008

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.

Highlight Area With mootools

10th February 2008

Creating a simple highlight effect is quite easy when you use the JavaScript framework mootools.

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.