|
|
recode_string (PHP 3 >= 3.0.13, PHP 4, PHP 5) recode_string -- Recode a string according to a recode request Descriptionstring recode_string ( string request, string string )
Recode the string string according to
the recode request request. Returns the
recoded string or FALSE, if unable to perform the recode request.
A simple recode request may be "lat1..iso646-de".
See also the GNU Recode documentation of your installation
for detailed instructions about recode requests.
Пример 1. Basic recode_string() example: |
<?php
echo recode_string("us..flat", "The following character has a diacritical mark: á");
?>
|
|
bisqwit at iki dot fi
23-Nov-2005 10:41
Here's how to convert romaji to katakana/hiragana with PHP (transliterating Japanese text).
The function Romaji2Kana($s) will return with keys 'hira' and 'kata' that respectively contain the hiragana and katakana versions of the given string in UTF-8 encoding.
<?php
define('HIRATABLE', 'a A i I u U e E o O KAGAKIGIKUGUKEGEKOGOSAZASIZISUZUSEZESOZO'.
'TADATIDItuTUDUTEDETODONANINUNENOHABAPAHIBIPIHUBUPUHEBEPEHOBOPO'.
'MAMIMUMEMOyaYAyuYUyoYORARIRUREROwaWAWIWEWOn ');
define('KATATABLE', 'a A i I u U e E o O KAGAKIGIKUGUKEGEKOGOSAZASIZISUZUSEZESOZO'.
'TADATIDItuTUDUTEDETODONANINUNENOHABAPAHIBIPIHUBUPUHEBEPEHOBOPO'.
'MAMIMUMEMOyaYAyuYUyoYORARIRUREROwaWAWIWEWOn VUkake');
function HiraTrans($s)
{
$pos = strpos(HIRATABLE, $s);
if($pos===false) return 0xA1BC; return 0xA4A1 + $pos/2;
}
function KataTrans($s)
{
$pos = strpos(KATATABLE, $s);
if($pos===false) return 0xA1BC; return 0xA5A1 + $pos/2;
}
function Romaji2Kana($s)
{
$s = strtoupper(str_replace(
Array('shi', 'sh', 'fu', 'chi', 'ch', 'tsu', 'dz', 'l', '-',
'
|
|