note 41126 added to function.mb-decode-numericentity
| From: | php at cNhOiSpPpAlMe dot org | Date: | Wed, 31 Mar 2004 05:55:29 +0000 |
| Subject: | note 41126 added to function.mb-decode-numericentity | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-67400@lists.php.net to get a copy of this message | ||
Here are functions to convert hankaku to zenkaku characters (and vice-versa) in Japanese text.
<?php
// Supported characters:
// (space)
// !#$%&()*+,./0123456789:;<=>?@
// ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`
// abcdefghijklmnopqrstuvwxyz{|}
// (Katakana isn't supported.)
function f_han2zen ($string,$encoding = null) {
if (is_null($encoding)) $encoding = mb_internal_encoding();
$convmap = array(
0x20,0x20,0x3000-0x20,0xffff, // Space
0x21,0x7e,0xff01-0x21,0xffff);
$temp = mb_encode_numericentity($string,$convmap,$encoding);
$convmap = array(0,0xffff,0,0xffff);
return mb_decode_numericentity($temp,$convmap,$encoding);
}
function f_zen2han ($string,$encoding = null) {
if (is_null($encoding)) $encoding = mb_internal_encoding();
$convmap = array(
0x3000,0x3000,-(0x3000-0x20),0xffff, // Space
0xff01,0xff5e,-(0xff01-0x21),0xffff);
$temp = mb_encode_numericentity($string,$convmap,$encoding);
$convmap = array(0,0xffff,0,0xffff);
return mb_decode_numericentity($temp,$convmap,$encoding);
}
// Sample usage:
f_han2zen("test","shift_jis");
f_han2zen("test","utf-8");
?>
----
Manual Page -- http://www.php.net/manual/en/function.mb-decode-numericentity.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41126
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41126&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41126&report=yes
Search -- http://master.php.net/manage/user-notes.php