Based on the original code and the answer to this question: How to get code point number for a given character in a utf-8 string? I put together this function:
function utf8_to_unicode($str) {
$unicode = array();
$values = array();
$lookingFor = 1;
for ($i = 0; $i < strlen($str); $i++) {
$thisValue = ord($str[$i]);
if ($thisValue < 128)
$unicode[] = str_pad(dechex($thisValue), 4, "0", STR_PAD_LEFT);
else {
if (count($values) == 0) $lookingFor = ($thisValue < 224) ? 2 : 3;
$values[] = $thisValue;
if (count($values) == $lookingFor) {
$number = ($lookingFor == 3) ?
(($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64):
(($values[0] % 32) * 64) + ($values[1] % 64);
$number = strtoupper(dechex($number));
$unicode[] = str_pad($number, 4, "0", STR_PAD_LEFT);
$values = array();
$lookingFor = 1;
} // if
} // if
} // for
return ($unicode);
} // utf8_to_unicode
So:
$greekString = "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ ";
$hexArray = utf8_to_unicode($greekString);
echo implode("", $hexArray);
Will output:
039103920393039403950396039703980399039A039B039C039D039E039F03A003A103A303A403A503A603A703A803A90032