note 38591 added to function.utf8-decode
| From: | lg83news at free dot fr | Date: | Mon, 29 Dec 2003 02:40:24 +0000 |
| Subject: | note 38591 added to function.utf8-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-62622@lists.php.net to get a copy of this message | ||
Here are some functions for converting UTF-8 to and from Latin 9 (aka ISO-8859-15), if your PHP file
is encoded as UTF-8.
<?php
function latin9_to_utf8($latin9str) { // replaces utf8_encode()
$trans = array("¤"=>"", "¦"=>"",
"¨"=>"", "´"=>"",
"¸"=>"", "¼"=>"",
"½"=>"", "¾"=>"");
$wrong_utf8str = utf8_encode($latin9str);
$utf8str = strtr($wrong_utf8str, $trans);
return $utf8str;
}
function utf8_to_latin9($utf8str) { // replaces utf8_decode()
$trans = array(""=>"¤", ""=>"¦",
""=>"¨", ""=>"´",
""=>"¸", ""=>"¼",
""=>"½", ""=>"¾");
$wrong_utf8str = strtr($utf8str, $trans);
$latin9str = utf8_decode($wrong_utf8str);
return $latin9str;
}
?>
Note: the above functions will not work if your PHP file is not encoded in UTF-8.
You can copy this binary data to your PHP file instead, it'll work with any encoding (including
UTF-8) as long as you copy it as bytes, not characters:
<?php
function latin9_to_utf8($latin9str) { // replaces utf8_encode()
$trans = array("¤"=>"â¬", "¦"=>"Å ",
"¨"=>"š", "´"=>"Ž",
"¸"=>"ž", "¼"=>"Å",
"½"=>"Å", "¾"=>"Ÿ");
$wrong_utf8str = utf8_encode($latin9str);
$utf8str = strtr($wrong_utf8str, $trans);
return $utf8str;
}
function utf8_to_latin9($utf8str) { // replaces utf8_decode()
$trans = array("â¬"=>"¤", "Å "=>"¦",
"š"=>"¨", "Ž"=>"´",
"ž"=>"¸", "Å"=>"¼",
"Å"=>"½", "Ÿ"=>"¾");
$wrong_utf8str = strtr($utf8str, $trans);
$latin9str = utf8_decode($wrong_utf8str);
return $latin9str;
}
?>
(Note: the PHP manual is served as ISO-8859-1, but many of the bytes used here have no meaning in
ISO-8859-1, so they'll probably be displayed as Windows-1252 if your using Windows, or garbage
otherwise. Just copy the bytes!)
----
Manual Page -- http://www.php.net/manual/en/function.utf8-decode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38591
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38591&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38591&report=yes
Search -- http://master.php.net/manage/user-notes.php