Jump to content

Decimal, Hexadecimal Character Codes


veluit06

Recommended Posts

These two functions might get you started

function Number_to_Character($number) {
if (function_exists('mb_convert_encoding')) {
	return mb_convert_encoding('&#'.intval($number).';', 'UTF-8', 'HTML-ENTITIES');
} else {
	return chr(intval($number));
}
}

function Character_to_Number($characters) {
if ((function_exists('mb_strlen')) && (function_exists('mb_substr'))) {
	if (mb_strlen($characters, 'UTF-8') > 0) {
		$character = mb_substr($characters, 0, 1, 'UTF-8');
		$byteLength = strlen($character);
		$xValue = 0;
		for ($i = 0; $i < $byteLength; ++$i) {
			$xValue = ($xValue * 256) + ord($character{$i});
		}
		return $xValue;
	}
} else {
	if (strlen($characters) > 0) {
		return ord(substr($characters, 0, 1));
	}
}
return false;
}

for some reason, it's sticking a spurious 38;# in line 3.... should be a simple '&#'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.