MaggsWeb:7

www.maggsweb.com

Archive for the ‘ PHP ’ Category

Remove all non alpha-numeric characters from a string.

<?php
    function alphanumericAndSpace( $string )
    {
        return preg_replace('/[^a-zA-Z0-9\s]/', '', $string);
    }
?>

I used to do this in about 6 lines.

$urlValues = explode(“/”, trim($_SERVER['SCRIPT_URL'], “/”));

Automated Tiny URL

September 24, 2010 | Comments | PHP

Function to create TinyURL’s on-the-fly
http://tinyurl.com/

[More]

A while ago I wrote my own RSS reader. It wasn’t that hard. But, occasionally you stumple across code like this example below that does the same thing as yours does, but sort of puts yours to shame. (Well, my version is about 3 years old now…).

So I cut down the original class and kept the bits I needed – and transferred all my implementations to the new method. Nothing changed on the front end, but I learnt a lot…

[More]

Very similar to the previous post on the same subject, but this time put into a ‘class’ file for neatness..
I have just used this on the new www.lady-drivers.co.uk site for sending Vouchers by email after subscribing.

[More]

Code commenting can be a pain. If its your code then you know exactly what it does and why. If its someone else’s code – then all of a sudden they are invaluable. The Doc Block commenting style is a widely used standard for commenting accross all languages, and can also be used to generate code hints and automatic documentation if used properly.

The following guide to code-commenting is taken from: http://net.tutsplus.com/tutorials/php/object-oriented-php-for-beginners/

[More]

I hate compressing CSS files as they become totally unreadable for editing. I end up keeping 2 versions, compressed and uncompressed, etc.. But how about compressing all your CSS files into one file, ‘on-the-fly’. Now that has solved the problem.

[More]

Just a little script I wrote to work out the date of the first day of the week.
[More]

PHP Sessions…

June 8, 2010 | Comments | PHP

Using $_SESSIONS… Forgot the syntax… Here-ya-go.
[More]

SEO is becoming more and more important, and URL’s need to be more visible. Here’s a function for creating a ‘slug’ which I used as an add-on to a site, using the page title.
[More]