hello,
Your solution is not good in generally. Why? This is working with letters with ASCII code under 256 (converted and displayed good) but letters with ASCII code over 256 I have "?" signs.
So We need to combine our two solutions in one 
example:
PHP Code:
function vbet_encodeToSafeUTF8(&$string) {
$string = preg_replace('/([\340-\357])([\200-\277])([\200-\277])/e',
'\'&#\'.((ord(\'\\1\')-224)*4096 + (ord(\'\\2\')-128)*64 + (ord(\'\\3\')-128)).\';\'',
$string);
//decode two byte unicode characters
$string = preg_replace('/([\304-\337])([\200-\277])/e',
'\'&#\'.((ord(\'\\1\')-192)*64+(ord(\'\\2\')-128)).\';\'',
$string);
$string = utf8_decode($string);
return $string;
}
this line: define than letters with ASCII code under 256 will be not decoded by my function but only by I am testing it still.I am not entirely sure that everything works correctly now.
You can test it too!