Преобразование строки с HEX-кодами к строке символов и обратно на PHP
Конвертирования строк HEX в String и String в HEX.
Пример:
Результат:
function hexToStr($hex) {
$string='';
for ($i=0; $i < strlen($hex)-1; $i+=2)
{
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}
function strToHex($string) {
$hex='';
for ($i=0; $i < strlen($string); $i++)
{
$hex .= dechex(ord($string[$i]));
}
return $hex;
}
Пример:
$hex = strToHex('VOVA1234');
$str = hexToStr($hex);
echo "Hex: ".$hex;
echo "<br>";
echo "String: ".$str;
Результат:
Hex: 564f564131323334
String: VOVA1234
String: VOVA1234



13.02.2015, 22:47 -
Категория: Статьи » Программирование » PHP