note 99949 deleted from function.utf8-decode by cmb
| From: | cmb@php.net | Date: | Sun, 11 Dec 2016 11:27:07 +0000 |
| Subject: | note 99949 deleted from function.utf8-decode by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208517@lists.php.net to get a copy of this message | ||
Note Submitter: mkluczka at gmail dot com
----
In jQuery AJAX requests, latin2 specific chars have 2B length, and common chars have 1B length.
PHP functions for UTF8->latin2 conversion didn't work for me, so I wrote this simple
function
to convert from jQuery AJAX encoding to ISO-8859-2 (latin2).
<?php
function jquery2iso($in)
{
$CONV = array();
$CONV['c4']['85'] = 'Ä
';
$CONV['c4']['84'] = 'Ä';
$CONV['c4']['87'] = 'Ä';
$CONV['c4']['86'] = 'Ä';
$CONV['c4']['99'] = 'Ä';
$CONV['c4']['98'] = 'Ä';
$CONV['c5']['82'] = 'Å';
$CONV['c5']['81'] = 'Å';
$CONV['c4']['84'] = 'Å';
$CONV['c4']['83'] = 'Å';
$CONV['c3']['b3'] = 'ó';
$CONV['c3']['93'] = 'Ã';
$CONV['c5']['9b'] = 'Å';
$CONV['c5']['9a'] = 'Å';
$CONV['c5']['ba'] = 'ź';
$CONV['c5']['b9'] = 'Ź';
$CONV['c5']['bc'] = 'ż';
$CONV['c5']['bb'] = 'Å»';
$i=0;
$out = '';
while($i<strlen($in))
{
if(array_key_exists(bin2hex($in[$i]), $CONV))
{
$out .= $CONV[bin2hex($in[$i])][bin2hex($in[$i+1])];
$i += 2;
}
else
{
$out .= $in[$i];
$i += 1;
}
}
return $out;
}
?>