note 55198 added to function.convert-cyr-string
| From: | cathody at mail dot ru | Date: | Wed, 27 Jul 2005 13:41:32 +0000 |
| Subject: | note 55198 added to function.convert-cyr-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92555@lists.php.net to get a copy of this message | ||
Praising other people for their efforts to write a convenient UTF8 to Win-1251 functions may I
mention that, since str_replace allows arrays as parameters, the function may be rewritten in a
slightly efficient way (moreover, the array generated may be stored for performance improvement):
<?php
function Encode ( $str, $type )
{
// $type:
// 'w' - encodes from UTF to win
// 'u' - encodes from win to UTF
static $conv='';
if (!is_array ( $conv ))
{
$conv=array ();
for ( $x=128; $x <=143; $x++ )
{
$conv['utf'][]=chr(209).chr($x);
$conv['win'][]=chr($x+112);
}
for ( $x=144; $x <=191; $x++ )
{
$conv['utf'][]=chr(208).chr($x);
$conv['win'][]=chr($x+48);
}
$conv['utf'][]=chr(208).chr(129);
$conv['win'][]=chr(168);
$conv['utf'][]=chr(209).chr(145);
$conv['win'][]=chr(184);
}
if ( $type=='w' )
return str_replace ( $conv['utf'], $conv['win'], $str );
elseif ( $type=='u' )
return str_replace ( $conv['win'], $conv['utf'], $str );
else
return $str;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.convert-cyr-string.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55198
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55198&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55198&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55198&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55198&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55198&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55198&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55198&report=yes
Search -- http://master.php.net/manage/user-notes.php