Turning ASCII Text Into HTML With PHP

25th April 2008

Providing a text box for users to type information in is very common, but usually people want to include line breaks and links with the text and they expect the site to lay it out just as they had intended it. The following function will turn any ASCII text string into the approximate HTML equivalent.

Insert Random Data Into Rabid Ratings

24th April 2008

Rabid Ratings is a neat ratings script written with the Mootools JavaScript framework that makes adding a rating function to any site very easy. The only problem is that when you first install the script it looks like no-one has ever visited your site to leave a rating. To combat this you can create lots of phony data that makes it look like your site is well visited and interesting. One way to do this is by getting lots of people to vote on every rating on the site.

Change MySQL Table Name

23rd April 2008

To change a table name in MySQL you can use the ALTER TABLE command with the parameter RENAME TO. Here is an example of a query that will rename the table "atable" to "newtable".

Preventing Image Bandwidth Theft With .htaccess

21st April 2008

When people link to your images from their own site they are essentially using your bandwidth to show images on their site, this is also known as hotlinking.

The simplest way of preventing people from doing this is to add a .htaccess file to only allow locally linked images to be served. This checks the domain that is linking to your images by using the referrer and if the domain does not equal you own site then a different image is served, in this case blank.jpg.

Debug Your PHP Applications With Krumo

20th April 2008

Krumo is an open source plugin for your programs that is designed as a replacement to print_r() and var_dump(). These functions are used by developers (myself included) to find out what the program is doing. The main problem is that if there is a lot of data to look at the page can get a bit busy.

Cut A String To A Specified Length With PHP

17th April 2008

Cutting a string to a specified length is accomplished with the substr() function. For example, the following string variable, which we will cut to a maximum of 30 characters.

Get Functions And Variables Of An Object With PHP

16th April 2008

It is possible to find out what functions and variables are available from an object at runtime using the PHP functions get_class_methods() and get_object_vars().

Take the following class called testClass.

Getting The Current URI In PHP

15th April 2008

The $_SERVER superglobal array contains lots of information about the current page location. You can print this off in full using the following line of code.