note 83238 added to function.iconv

From: Date: Fri, 16 May 2008 10:17:58 +0000
Subject: note 83238 added to function.iconv
Groups: php.notes 
Request: Send a blank email to php-notes+get-139439@lists.php.net to get a copy of this message
If you need to strip as many national characters from UTF-8 as possible and keep the rest of input unchanged (i.e. convert whatever can be converted to ASCII and leave the rest), you can do it like this: <?php setlocale(LC_ALL, 'en_US.UTF8'); function clearUTF($s) { $r = ''; $s1 = iconv('UTF-8', 'ASCII//TRANSLIT', $s); for ($i = 0; $i < strlen($s1); $i++) { $ch1 = $s1[$i]; $ch2 = mb_substr($s, $i, 1); $r .= $ch1=='?'?$ch2:$ch1; } return $r; } echo clearUTF('Šíleně žluťoučký Vašek úpěl olol! This will remain untranslated: ᾡᾧῘઍિ૮'); //outputs Silene zlutoucky Vasek upel olol! This will remain untranslated: ᾡᾧῘઍિ૮ ?> Just remember you HAVE TO set locale to some unicode encoding to make iconv handle //TRANSLIT correctly! ---- Server IP: 147.32.160.17 Probable Submitter: 90.177.222.45 ---- Manual Page -- http://www.php.net/manual/en/function.iconv.php Edit -- https://master.php.net/note/edit/83238 Del: integrated -- https://master.php.net/note/delete/83238/integrated Del: useless -- https://master.php.net/note/delete/83238/useless Del: bad code -- https://master.php.net/note/delete/83238/bad+code Del: spam -- https://master.php.net/note/delete/83238/spam Del: non-english -- https://master.php.net/note/delete/83238/non-english Del: in docs -- https://master.php.net/note/delete/83238/in+docs Del: other reasons-- https://master.php.net/note/delete/83238 Reject -- https://master.php.net/note/reject/83238 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139439) next »