You are here: Re: Best way to encode? « PHP « IT news, forums, messages
Re: Best way to encode?

Posted by Sephiroth on 01/21/05 04:14

in HTML with HTTP_GET, you can use:
xxx.href = "my.php?data="+encodeURI(escape("...foreign strings..."));

my.php:

$data = uniDecode($_GET["data"]);
echo $data;



function uniDecode($sText) {
$sData = preg_replace_callback("/%u[0-9A-Za-z]{4}/",toUtf8, $sText);
return unescape($sData);
}

function toUtf8($ar) {
$c = "";
foreach($ar as $val) {
$val = intval(substr($val,2),16);
if($val < 0x7F){ // 0000-007F
$c .= chr($val);
}
elseif ($val < 0x800) { // 0080-0800
$c .= chr(0xC0 | ($val / 64));
$c .= chr(0x80 | ($val % 64));
}
else { // 0800-FFFF
$c .= chr(0xE0 | (($val / 64) / 64));
$c .= chr(0x80 | (($val / 64) % 64));
$c .= chr(0x80 | ($val % 64));
}
}
return $c;
}

function unescape($sText) {
$sTranArray = array("%09" => "\t",
"%0A" => "\n",
"%0B" => "\x0b",
"%0D" => "\r",
"%20" => " ",
"%21" => "!",
"%22" => "\"",
"%23" => "#",
"%24" => "$",
"%25" => "%",
"%26" => "&",
"%27" => "'",
"%28" => "(",
"%29" => ")",
"%2C" => ",",
"%3A" => ":",
"%3B" => ";",
"%3C" => "<",
"%3D" => "=",
"%3E" => ">",
"%3F" => "?",
"%5C" => "\\",
"%5B" => "[",
"%5D" => "]",
"%5E" => "^",
"%60" => "`",
"%7C" => "|",
"%7B" => "{",
"%7D" => "}",
"%7E" => "~");
return strtr($sText, $sTranArray);
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация