PHP: mb_convert_kana - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

mb_convert_variables mb_convert_encoding

Last updated: Sat, 27 Jan 2007

view this page in

# mb_convert_kana

(PHP 4 >= 4.0.6, PHP 5)

mb_convert_kana -- Convert "kana" one from another ("zen-kaku", "han-kaku" and more)

## Description

string mb_convert_kana ( string str [, string option [, string encoding]] )

mb_convert_kana() performs "han-kaku" - "zen-kaku" conversion for string `str`. It returns converted string. This function is only useful for Japanese.

`option` is conversion option. Default value is `"KV"`.

`encoding` is character encoding. If it is omitted, internal character encoding is used.

Specify with combination of following options. Default value is `KV`.

Таблица 1. Applicable Conversion 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"

Пример 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");
?>`

add a note User Contributed Notes
mb_convert_kana
d at safetypub dot org
01-Apr-2005 03:00
`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
23-Jul-2003 09:33
`It seems that mb_convert_kana() doesn't convert symbols such as ' (single quoatation). It affected my program when I insert data into database.
So, I've found 2 ways to solve this.
1) Use Javascript to convert those non-supported symbols before sending query string to your php page.
2) Use php function, str_replace $str, to replace those non-supported symbols. For example, $str = str_replace("'", "�", $str);
where the first single quot is half-width(han kaku), and the second one is full-width(zen kaku).`
add a note
mb_convert_variables mb_convert_encoding

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST