(PHP 4 >= 4.0.6, PHP 5)
mb_convert_kana — Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
$str
[, string $option
= "KV"
[, string $encoding
]] )
Performs a "han-kaku" - "zen-kaku" conversion for string str
.
This function is only useful for Japanese.
str
The string being converted.
option
The conversion option.
Specify with a combination of following options.
Option | Meaning |
---|---|
r | Convert "zen-kaku" alphabets to "han-kaku" |
R | Convert "han-kaku" alphabets to "zen-kaku" |
n | Convert "zen-kaku" numbers to "han-kaku" |
N | Convert "han-kaku" numbers to "zen-kaku" |
a | Convert "zen-kaku" alphabets and numbers to "han-kaku" |
A | Convert "han-kaku" alphabets and numbers to "zen-kaku" (Characters included in "a", "A" options are U+0021 - U+007E excluding U+0022, U+0027, U+005C, U+007E) |
s | Convert "zen-kaku" space to "han-kaku" (U+3000 -> U+0020) |
S | Convert "han-kaku" space to "zen-kaku" (U+0020 -> U+3000) |
k | Convert "zen-kaku kata-kana" to "han-kaku kata-kana" |
K | Convert "han-kaku kata-kana" to "zen-kaku kata-kana" |
h | Convert "zen-kaku hira-gana" to "han-kaku kata-kana" |
H | Convert "han-kaku kata-kana" to "zen-kaku hira-gana" |
c | Convert "zen-kaku kata-kana" to "zen-kaku hira-gana" |
C | Convert "zen-kaku hira-gana" to "zen-kaku kata-kana" |
V | Collapse voiced sound notation and convert them into a character. Use with "K","H" |
encoding
encoding
参数为字符编码。如果省略,则使用内部字符编码。
The converted string.
Example #1 mb_convert_kana() example
<?php
/* Convert all "kana" to "zen-kaku" "kata-kana" */
$str = mb_convert_kana($str, "KVC");
/* Convert "han-kaku" "kata-kana" to "zen-kaku" "kata-kana"
and "zen-kaku" alpha-numeric to "han-kaku" */
$str = mb_convert_kana($str, "KVa");
?>
jdavide222 at hotmail dot com (2013-03-11 04:02:00)
to make this function work you have to add following two lines above this function.
mb_language("Ja");
mb_internal_encoding("utf-8");
mb_convert_kana($_POST['something_value'], "rna");
sohel62 at yahoo dot com (2008-02-18 21:17:57)
I did that manually when I was not getting expected result using mb_convert_kana().
<?php
/*
* @author Taslim Mazumder Sohel
* @deprecated 1.0 - 2008/02/19
*
*/
function han_kaku_to_jen_kaku($str){
$replace_of = array('??','??','??','??',
'??','??','??','??',
'??','??','??','??',
'??','??','??','??',
'??','??','??','??',
'??','??','??','??','??','??');
$replace_by = array('ヴ','ガ','ギ','グ',
'ゲ','ゴ','ザ','ジ',
'ズ','ゼ','ゾ','ダ',
'ヂ','ヅ','デ','ド',
'バ','ビ','ブ','ベ',
'ボ','パ','ピ','プ','ペ','ポ');
$_result = str_replace($replace_of, $replace_by, $str);
$replace_of = array('?','?','?','?','?',
'?','?','?','?','?',
'?','?','?','?','?',
'?','?','?','?','?',
'?','?','?','?','?',
'?','?','?','?','?',
'?','?','?','?','?',
'?','?','?','?','?',
'?','?','?','?','?',
'?','?','?','?','?',
'?','ヵ','ヶ','?','?',
'?','?','?','?','?',
'?','?','?','?');
$replace_by = array('ア','イ','ウ','エ','オ',
'カ','キ','ク','ケ','コ',
'サ','シ','ス','セ','ソ',
'タ','チ','ツ','テ','ト',
'ナ','ニ','ヌ','ネ','ノ',
'ハ','ヒ','フ','ヘ','ホ',
'マ','ミ','ム','メ','モ',
'ヤ','ユ','ヨ','ラ','リ',
'ル','レ','ロ','ワ','ヲ',
'ン','ァ','ィ','ゥ','ェ',
'ォ','ヶ','ヶ','ャ','ュ',
'ョ','ッ','、','。','ー',
'「','」','”','');
$_result = str_replace($replace_of, $replace_by, $_result);
return $_result;
}
?>
d at safetypub dot org (2005-04-01 03:00:19)
I didn't find Japanese sorting function.
(mb_sort_kana or something)
Only SJIS encoding treats hankaku kata kana,
I can't post here copy & paste version script.
I'm sorry...
You will replace comments with appropriate japanese string,
and write exception handlings between lines as you like.
<?php
mb_internal_encoding("SJIS");
$moji = /*"aiueo...wawon -?.," <- serialized hankaku kata kana 50 on hyou goes here*/;
$moji .= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxwz0123456789";
for($i = 0; isset($moji[$i]); $i++){
$pittan[$moji[$i]] = $i;
}
function cmp($a, $b)
{
if ($a == $b) {
return 0;
}
return iter(mb_convert_kana($a, "askh") ,mb_convert_kana($b, "askh"), 0);
}
function iter($a, $b, $i){
global $pittan;
if(!isset($a[$i]) || !isset($b[$i])){
return (isset($b[$i]))? -1 : 1;
}
if ($pittan[$a[$i]] == $pittan[$b[$i]]){
return iter($a, $b, ++$i);
}
return (($pittan[$a[$i]]) < ($pittan[$b[$i]]))? -1 : 1;
}
echo "<pre>";
$arr = array(/*some japanese array here*/);
usort($arr, "cmp");
var_dump($arr);
?>
dn at littlealf dot net (2003-07-23 21:33:52)