ikl file e questo come posso modificare anche senza l'unicode?
<?
/*******************************************
ALTRO
*******************************************/
include "include/regioni.inc.php";
function code2utf($num){
if($num<128)return chr($num);
if($num<1024)return chr(($num>>6)+192).chr(($num&63)+128);
if($num<32768)return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($ num&63)+128);
if($num<2097152)return chr($num>>18+240).chr((($num>>12)&63)+128).chr(($n um>>6)&63+128). chr($num&63+128);
return '';
}
function entities_to_unicode( $str ) {
$unicode = array();
$inEntity = FALSE;
$entity = '';
for ($i = 0; $i < strlen( $str ); $i++ ) {
if ( $inEntity ) {
if ( $str[ $i ] == ';' ) {
$unicode[] = (int)$entity;
$entity = '';
$inEntity = FALSE;
} elseif ( $str[ $i ] != '#' ) {
$entity .= $str[ $i ];
} // if
} else {
if ( ( $str[ $i ] == '&' )&&( $str[ $i + 1 ] == '#' ) ) $inEntity = TRUE;
else $unicode[] = ord( $str[ $i ] );
} // if
} // for
return $unicode;
} // entities_to_unicode
function unicode_to_utf8_chr($uc)
{
if ($uc < 0x80)
return chr($uc);
else if ($uc < 0x800) {
$u2 = 0xC0 | $uc >> 6;
$u1 = 0x80 | $uc & 0x3F;
$ret = chr($u2) . chr($u1);
return $ret;
} else if ($uc < 0x10000) {
$u3 = 0xE0 | $uc >> 12;
$u2 = 0x80 | $uc >> 6 & 0x3F;
$u1 = 0x80 | $uc & 0x3F;
return chr($u3).chr($u2).chr($u1);
} else if ($uc < 0x200000) {
$u4 = 0xF0 | $uc >> 18;
$u3 = 0x80 | $uc >> 12 & 0x3F;
$u2 = 0x80 | $uc >> 6 & 0x3F;
$u1 = 0x80 | $uc & 0x3F;
return chr($u4).chr($u3).chr($u2).chr($u1);
}
return 0;
}
function unicode_to_utf8_chr_2( $unicode_hex ) {
$unicode = $unicode_hex;
$utf8 = '';
if ( $unicode < 128 ) {
$utf8 = chr( $unicode );
} elseif ( $unicode < 2048 ) {
$utf8 .= chr( 192 + ( ( $unicode - ( $unicode % 64 ) ) / 64 ) );
$utf8 .= chr( 128 + ( $unicode % 64 ) );
} else {
$utf8 .= chr( 224 + ( ( $unicode - ( $unicode % 4096 ) ) / 4096 ) );
$utf8 .= chr( 128 + ( ( ( $unicode % 4096 ) - ( $unicode % 64 ) ) /
64 ) );
$utf8 .= chr( 128 + ( $unicode % 64 ) );
} // if
return $utf8;
} // unicode_to_utf8
function unicode_to_utf8( $str ) {
$utf8 = '';
foreach( $str as $unicode ) {
$utf8.=unicode_to_utf8_chr($unicode);
} // foreach
return $utf8;
} // unicode_to_utf8
// Converte un carattere codificato Unicode in una entità html (&#num
// Funzione inversa by leon
function utf2code($chr) {
$open = false;
for ($a = 0; $a < strlen($chr); $a++)
{
$num = ord(substr($chr,$a,1));
if ($num < 128)
{
if ($open == true) {
if (strlen($utf)==2) {
$code=((ord(substr($utf, 0, 1))-192)<<6)+(((ord(substr($utf, 1, 1))-128)&63));
}
if (strlen($utf)==3) {
$code=((ord(substr($utf, 0, 1))-224)<<12)+(((ord(substr($utf, 1, 1))-128)&63)<<6)+(((ord(substr($utf, 2, 1))-128)&63));
}
if (strlen($utf)==4) {
$code=((ord(substr($utf, 0, 1))-240)<<18)+(((ord(substr($utf, 1, 1))-128)&63)<<12)+(((ord(substr($utf, 2, 1))-128)&63)<<6)+(((ord(substr($utf, 3, 1))-128)&63));
}
$utf="";
$str.="&#".$code.";";
}
$str.=chr($num);
$open=false;
} else {
if ($open == true) {
$cv=false;
if ($num > 240) {
$cv=true;
$code=((ord(substr($utf, 0, 1))-240)<<18)+(((ord(substr($utf, 1, 1))-128)&63)<<12)+(((ord(substr($utf, 2, 1))-128)&63)<<6)+(((ord(substr($utf, 3, 1))-128)&63));
}
if ($num > 224) {
$cv=true;
$code=((ord(substr($utf, 0, 1))-224)<<12)+(((ord(substr($utf, 1, 1))-128)&63)<<6)+(((ord(substr($utf, 2, 1))-128)&63));
}
if ($num > 192) {
$code=((ord(substr($utf, 0, 1))-192)<<6)+(((ord(substr($utf, 1, 1))-128)&63));
$cv=true;
}
if ($cv == true) {
$utf="";
$str.="&#".$code.";";
}
}
$open=true;
$utf.=chr($num);
}
}
if ($open == true)
{
if (strlen($utf)==2) {
$code=((ord(substr($utf, 0, 1))-192)<<6)+(((ord(substr($utf, 1, 1))-128)&63));
}
if (strlen($utf)==3) {
$code=((ord(substr($utf, 0, 1))-224)<<12)+(((ord(substr($utf, 1, 1))-128)&63)<<6)+(((ord(substr($utf, 2, 1))-128)&63));
}
if (strlen($utf)==4) {
$code=((ord(substr($utf, 0, 1))-240)<<18)+(((ord(substr($utf, 1, 1))-128)&63)<<12)+(((ord(substr($utf, 2, 1))-128)&63)<<6)+(((ord(substr($utf, 3, 1))-128)&63));
}
$utf="";
$str.="&#".$code.";";
}
return $str;
}
function unicode2html($str)
{
return utf2code($str);
$str2=$str;
for ($a = 128; $a < 65536; $a++)
$str2=str_replace(code2utf($a),"&#".$a.";",$str2);
return $str2;
}
function convert_html($str)
{
$open = false;
for ($a = 0; $a < strlen($str); $a++)
{
$ch = substr($str, $a, 1);
if ($open == true) {
$x.= $ch;
if ($ch == ";")
{
$open = false;
$res.=$x;
}
continue;
}
if (substr($str, $a, 2) == "&#") { $open = true; $a+= 1; $x = "&#"; continue; }
$res.="&#".ord($ch).";";
}
return $res;
}
function html2unicode($str)
{
$nick = escapeshellarg($str);
$nick = stripslashes($nick);
@unlink("/inetpub/wwwroot/unicode/result.txt");
@exec("/inetpub/wwwroot/unicode/uni_cgi.exe $nick");
$nick = file("/inetpub/wwwroot/unicode/result.txt");
$nick = substr(trim($nick[0]),1);
$nick = substr($nick, 0, strlen($nick)-1);
return $nick;
}/*
function gb2unicode($gb)
{
if(!trim($gb))
return $gb;
$filename="gb2312.txt";
$tmp=file($filename);
$codetable=array();
$gb=".".$gb;
while(list($key,$value)=each($tmp))
$codetable[hexdec(substr($value,0,6))]=substr($value,9,4);
$utf="";
while($gb)
{
if (ord(substr($gb,0,1))>127)
{
$this=substr($gb,0,2);
$gb=substr($gb,2,strlen($gb));
$utf.="&#x".$codetable[hexdec(bin2hex($this))-0x8080].";";
}
else
{
$gb=substr($gb,1,strlen($gb));
$utf.=substr($gb,0,1);
}
}
return $utf;
}*/


Rispondi quotando