Tag Archives: conversion

Easily convert MySQL database collations and alter character sets

I can’t remember what all I looked at for references, but this completed tool will generate the SQL  commands necessary to convert your database, tables and fields from any collation and character set into another.

It goes without saying to make a backup of your database before running such commands. If you don’t make a backup first, shame on you 😛 Continue reading

Simple PHP function to convert hexadecimal colors to RGB (red, green, blue) decimal values

This function will convert hexadecimal colors with a length of 6, 3, 2, or 1 into their RGB decimal equivalents. If a value cannot be converted, it defaults to black…

function hex2rgb($hex = NULL) {
	preg_match('/^#{0,1}([0-9a-f]{1,6})$/i', $hex, $matches);
	if ($hex[0] == '#') $hex = substr($hex, 1);
	$length = @strlen($matches[1]);
	switch ($length) {
		case 6:
			$rgb = array($hex[0] . $hex[1], $hex[2] . $hex[3], $hex[4] . $hex[5]);
			break;
		case 3:
			$rgb = array($hex[0] . $hex[0], $hex[1] . $hex[1], $hex[2] . $hex[2]);
			break;
		case 2:
			$rgb = array($hex[0] . $hex[1], $hex[0] . $hex[1], $hex[0] . $hex[1]);
			break;
		default:
			$hex = ($length == 1) ? $hex . $hex : 0;
			$rgb = array($hex, $hex, $hex);
			break;
	}
	return array(
		'r' => hexdec($rgb[0]),
		'g' => hexdec($rgb[1]),
		'b' => hexdec($rgb[2])
	);
}

Short, simple and sweet 🙂

Calculator: Convert Xbox Live Microsoft Points (MSP) to USD

Here is a calculator (requires JavaScript) to convert Xbox Live Microsoft Points into USD (dollars) and vice versa.

Microsoft Point Converter

USD MSP

Simply enter an amount into either field and the conversion is automatic.

PS: If you leech my code, at least link to me for credit 😉

Codeigniter Image_lib convert() v1.3 JPG to GIF to PNG

I recently performed some code-fixing for a library extension I found over in CodeIgniter’s forum. The mod provided a convert() method for the Image_lib library. It lets you to convert (duh) the original image from/to JPG (default), GIF or PNG and optionally delete the original image.

When I first added this extension into my CI distribution, everything still worked without throwing errors so I started calling the new function. Then…

Continue reading

Convert extended ASCII in a string using PHP strtr instead of Normalizer or iconv

I am working on a CodeIgniter project that has information stored in the database with extended ascii characters (128-255) and UTF-8 encoding. As most of you know, CodeIgniter is fairly strict on what is allowed in a url (they only allow what SHOULD be permitted per RFC 1738 ;)). Furthermore sunce you can create basically any character by allowing a percent sign (%) in the URL, alowing that was not a viable option for me.

For instance you cannot use “ñ” (n with a tilde) in the URL parameters. Replacing it with “n” for the database query will however return a valid match. Problem solved! I can just use Normalizer or iconv, right?

Continue reading

Fractions to Decimal Conversion Table

Since I deal a lot with designing artwork in US measurements (fractions) using Illustrator and Photoshop, more often than not I have to break out a calculator to determine the decimal value of a fractional measurement.

Lets say I need to create a document that is 4 inches wide by 3 7/16 inches high. Obviously 4 inches needs no conversion, but then you have the 3 7/16 inches measurement. First you take 1, divide it by 16, then multiply the result by 7… what a pain.

So I have thrown together a quick reference guide that start at 1/64 and goes up to 63/64 with each variation in between. Bookmark or print this page to save a copy for your own personal reference. The most common fractions for my purposes are outlined in bold.

Continue reading