Skip Navigation

Everything tagged with "code"

The fourth part of the Writing Secure PHP series, covering cross-site scripting, cross-site request forgery and character encoding security issues.

Read the rest of this post »

Adding and removing variables to and from URLs using PHP can be a relatively simple process admittedly, but I have a couple of functions I use often to make the process even less time-consuming.

Add Querystring Variable

A PHP function that will add the querystring variable $key with a value $value to $url. If $key is already specified within $url, it will replace it.

function add_querystring_var($url, $key, $value) {
    $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
    $url = substr($url, 0, -1);
    if (strpos($url, '?') === false) {
        return ($url . '?' . $key . '=' . $value);
    } else {
        return ($url . '&' . $key . '=' . $value);
    }
}

Remove Querystring Variable

A PHP function that will remove the variable $key and its value from the given $url.

function remove_querystring_var($url, $key) {
    $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
    $url = substr($url, 0, -1);
    return ($url);
}

RSS to iCal


19 October 2006   |   Comments   |   rss, weather, php, bbc, ical, convert, tools, web, webdev, code, rss2ical

I have been looking for a way to convert the BBC weather feed for my area to iCal, so I can subscribe to it. It's date-based, after all, and RSS never seemed to me to be an appropriate format for subscribing to weather information. iCal always struck me as being "better" for that purpose. Of course, the BBC only have an RSS feed for local weather. What I needed was a converter.

After some hunting, I discovered that Dean Sanvitale had written a PHP script to convert RSS feeds to iCal format. However, his site (codent.com) appears to be long since abandoned and the script is no longer available from there. Fortunately, the Wayback Machine did have a copy. Dean originally released the script under a Creative Commons License which, fortunately, allows me to make the script available to download from this site (note: the script is available from this site under the same license).

So, if you're looking for a way to convert an RSS feed to iCal, this PHP script will do the job. Thanks Dean!

Source: rss2ical.txt

Regular Expressions are very powerful, and many people find their unusual syntax hard to get to grips with. This A4 reference serves as a guide to regular expression patterns and options.

Read the rest of this post »

A quick reference guide for JavaScript, listing methods and functions, and including a guide to regular expressions and the XMLHttpRequest object.

Read the rest of this post »

I'm fed up with having to visit php.net to look things up. This A4 cheat sheet is designed to sit by your desk and make your life easier.

Read the rest of this post »

How to preload images using CSS and so avoid delays with rollover effects.

Read the rest of this post »

A tool that outputs the structure of a page. Makes working with CSS (especially resolving inheritance issues) much easier.

Read the rest of this post »

Learn how to avoid some of the most common mistakes in PHP, and so make your sites more secure.

Read the rest of this post »

The Gunning-Fog Index is a measure of text readability based upon sentence length and difficult words in a passage.

Read the rest of this post »

High-traffic sites can often benefit from caching of pages, to save processing of the same data over and over again. This caching tutorial runs through the basics of file caching in PHP.

Read the rest of this post »

How to validate email addresses according to ISO standards with PHP.

Read the rest of this post »

Regular expression reference and examples for VBScript.

Read the rest of this post »