1
PHP / Помогите пожалуйста... & # 1086 надо перевести в символы... Очень нужно
« : 09 Ноября 2005, 13:30:26 »
Вот, может кому-нить еще пригодится
<?php function uc2html($str) {
$ret = \'\';
for( $i=0; $i<strlen($str)/2; $i++ ) {
$charcode = ord($str[$i*2])+256*ord($str[$i*2+1]);
$ret .= \'&#\'.$charcode;
}
return HTMLtoKOI($ret);
}
function HTMLtoKOI($str){
$str = preg_replace(\'~&#(\\d+)~se\',\'html_entity_decode("$0".";",ENT_QUOTES,"CP1251")\',$str);
$str = str_replace(";","",$str);
$str = preg_replace(\'~&#(\\d+)~se\',\'\\\\1>1103 ? "\\\\0;" : (\\\\1>848 ? chr(\\\\1-848) : chr(\\\\1))\',$str);
return trim($str);
} ?>
<?php function uc2html($str) {
$ret = \'\';
for( $i=0; $i<strlen($str)/2; $i++ ) {
$charcode = ord($str[$i*2])+256*ord($str[$i*2+1]);
$ret .= \'&#\'.$charcode;
}
return HTMLtoKOI($ret);
}
function HTMLtoKOI($str){
$str = preg_replace(\'~&#(\\d+)~se\',\'html_entity_decode("$0".";",ENT_QUOTES,"CP1251")\',$str);
$str = str_replace(";","",$str);
$str = preg_replace(\'~&#(\\d+)~se\',\'\\\\1>1103 ? "\\\\0;" : (\\\\1>848 ? chr(\\\\1-848) : chr(\\\\1))\',$str);
return trim($str);
} ?>