note 99949 added to function.utf8-decode

From: Date: Thu, 16 Sep 2010 11:36:09 +0000
Subject: note 99949 added to function.utf8-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-172633@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 82.177.164.100 Probable Submitter: 77.253.201.39 ---- Manual Page -- http://www.php.net/manual/en/function.utf8-decode.php Edit -- https://master.php.net/note/edit/99949 Del: integrated -- https://master.php.net/note/delete/99949/integrated Del: useless -- https://master.php.net/note/delete/99949/useless Del: bad code -- https://master.php.net/note/delete/99949/bad+code Del: spam -- https://master.php.net/note/delete/99949/spam Del: non-english -- https://master.php.net/note/delete/99949/non-english Del: in docs -- https://master.php.net/note/delete/99949/in+docs Del: other reasons-- https://master.php.net/note/delete/99949 Reject -- https://master.php.net/note/reject/99949 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172633) next »