Wednesday, June 24, 2009

How to validate a hex color in PHP

Validating a hex color code in PHP is easy.

Rules:

Hex colors must start with '#' and have 6 characters.
Hex colors can contain the following letters: [A-F]
Hex colors can contain the following digits: [0-9]

So using pregmatch, the hex validation code is:

if(preg_match('/^#[a-f0-9]{6}$/i', $color)) //hex color is valid
{

}

Tuesday, June 23, 2009

PHP Upload and Image Manipulation Class

I've been looking for a simple to use class for uploading and manipulating images. And I have found it.

Here it is: http://www.verot.net/php_class_upload_overview.htm

You can upload files, validate mime types, set language for errors. It's really easy to use. It's free for non-commercial applications.

You can now easily upload and manipulate images (resize, watermark, etc) with this PHP class.