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");
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
mb_convert_kana — Convertit un "kana" en un autre ("zen-kaku", "han-kaku" et plus)
Effectue une conversion "han-kaku" - "zen-kaku" sur la chaîne
string
. Cette fonction est uniquement utile pour les japonais.
string
La chaîne à convertir.
mode
L'option de conversion.
Spécifiez les conversions en combinant les valeurs suivantes.
Option | Signification |
---|---|
r |
Convertit l'alphabet "zen-kaku" en "han-kaku" |
R |
Convertit l'alphabet "han-kaku" en "zen-kaku" |
n |
Convertit les nombres "zen-kaku" en "han-kaku" |
N |
Convertit les nombres "han-kaku" en "zen-kaku" |
a |
Convertit les nombres et alphabet "zen-kaku" en "han-kaku" |
A |
Convertit les nombres et alphabet "zen-kaku" en "han-kaku". (Les caractères inclus dans les options "a", "A" sont U+0021 - U+007E en excluant U+0022, U+0027, U+005C, U+007E) |
s |
Convertit "zen-kaku" en "han-kaku" (U+3000 -> U+0020) |
S |
Convertit "han-kaku" en "zen-kaku" (U+0020 -> U+3000) |
k |
Convertit "zen-kaku kata-kana" en "han-kaku kata-kana" |
K |
Convertit "han-kaku kata-kana" en "zen-kaku kata-kana" |
h |
Convertit "zen-kaku hira-gana" en "han-kaku kata-kana" |
H |
Convertit "han-kaku kata-kana" en "zen-kaku hira-gana" |
c |
Convertit "zen-kaku kata-kana" en "zen-kaku hira-gana" |
C |
Convertit "zen-kaku hira-gana" en "zen-kaku kata-kana" |
V |
Supprime les notations vocales, et les convertit en caractères. À utiliser avec "K","H" |
encoding
Le paramètre encoding
est l'encodage des caractères. S'il est omis ou null
, l'encodage de caractères interne
sera utilisé.
La chaîne convertie.
Lance une ValueError si la combinaison de
différents mode
n'est pas valide.
Par exemple "sS"
.
Version | Description |
---|---|
8.2.0 |
Une ValueError est désormais lancée si la
combinaison de différents mode s n'est pas valide.
|
8.0.0 |
encoding est désormais nullable.
|
Exemple #1 Exemple avec mb_convert_kana()
<?php
/* Convertit tous les "kana" en "zen-kaku" "kata-kana" */
$str = mb_convert_kana($str, "KVC");
/* Convertit "han-kaku" "kata-kana" en "zen-kaku" "kata-kana"
et "zen-kaku" alphanumérique en "han-kaku" */
$str = mb_convert_kana($str, "KVa");
?>
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");
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.<?phpmb_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);?>
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).