note 94801 added to function.utf8-decode
| From: | andrew at osu1 dot php dot net | Date: | Wed, 25 Nov 2009 16:13:58 +0000 |
| Subject: | note 94801 added to function.utf8-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-163271@lists.php.net to get a copy of this message | ||
a simple function to convert encoding that appears mixed.
$trans = new Latin1UTF8();
$mixed = "MIXED TEXT INPUT";
print "Original: ".$mixed;
print "Latin1: ".$trans->mixed_to_latin1($mixed);
print "UTF-8: ".$trans->mixed_to_utf8($mixed);
class Latin1UTF8 {
private $latin1_to_utf8;
private $utf8_to_latin1;
public function __construct() {
for($i=32; $i<=255; $i++) {
$this->latin1_to_utf8[chr($i)] = utf8_encode(chr($i));
$this->utf8_to_latin1[utf8_encode(chr($i))] = chr($i);
}
}
public function mixed_to_latin1($text) {
foreach( $this->utf8_to_latin1 as $key => $val ) {
$text = str_replace($key, $val, $text);
}
return $text;
}
public function mixed_to_utf8($text) {
return utf8_encode($this->mixed_to_latin1($text));
}
}
----
Server IP: 87.124.86.46
Probable Submitter: 86.173.109.245 (proxied: 86.173.109.245)
----
Manual Page -- http://www.php.net/manual/en/function.utf8-decode.php
Edit -- https://master.php.net/note/edit/94801
Del: integrated -- https://master.php.net/note/delete/94801/integrated
Del: useless -- https://master.php.net/note/delete/94801/useless
Del: bad code -- https://master.php.net/note/delete/94801/bad+code
Del: spam -- https://master.php.net/note/delete/94801/spam
Del: non-english -- https://master.php.net/note/delete/94801/non-english
Del: in docs -- https://master.php.net/note/delete/94801/in+docs
Del: other reasons-- https://master.php.net/note/delete/94801
Reject -- https://master.php.net/note/reject/94801
Search -- https://master.php.net/manage/user-notes.php