Archive for the 'Code snippets' Category

Page 2 of 2

Create a random thumbnail of a video file

Create a random thumbnail of a video file

Looking at sites like YouTube, you may think it’s quite hard to create a lot of different thumbnails from video files, and have them from random times within that file. But, no, it’s not! As this article shows, by using the very fabulous FFmpeg library, it’s actually a very short amount of code that’s required to create all those lovely random thumbnails.

Continue reading ‘Create a random thumbnail of a video file’

Did you like this? Share it:

Create a registration key

This simple function allows you to generate a random registration key in the format, ’1224-54B1-7D35-5EF7′.

function registration_key()
{
    return strtoupper(substr(chunk_split(sprintf('%03d%s',
                      rand(0,999), uniqid('')), 4, '-'), 0, -1));
}
Did you like this? Share it:

Validate a UK postcode

You’ve probably seen this before, if not a thousand times, but here’s a simple function to check the format of a UK postcode.

function valid_uk_postcode($postcode)
{
    return (preg_match('/^([A-PR-UWYZ][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {0,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$/i', $postcode)) ?
        true : false;
}
Did you like this? Share it: