mb_convert_kana()是PHP中的內置函數,用於將文本轉換為full-width和half-width。
用法:
mb_convert_kana($string, $mode, $encoding) : string
參數:
該函數接受下麵說明的三個參數。
- $字符串:這是我們要使用此函數轉換的字符串.
 - $模式:該參數指定不同的轉換選項。
 - $編碼:該參數是可選的。如果您不指定編碼,那麽它將使用mb_internal_encoding()函數編碼。
 
返回值:
此mb_convert_kana() 函數返回轉換後的字符串。
程序1:下麵的程序演示了mb_convert_kana()函數。
PHP
<?php 
    
// Input string 
$input = "Hello, world!"; 
  
// Convert to full-width form 
$converted = mb_convert_kana($input, "A", "UTF-8"); 
  
// Output the converted string 
echo $converted; 
?>輸出
Hello, world!
程序2:下麵的程序演示了mb_convert_kana()函數。
PHP
<?php 
    
// Input string 
$input = "12345"; 
$convertToFullWidth = true; 
  
// Conditionally convert the string to full-width form 
if ($convertToFullWidth) { 
    $converted = mb_convert_kana($input, "N", "UTF-8"); 
} else { 
    $converted = $input; 
} 
  
// Output the converted string 
echo $converted; 
?>輸出
12345
程序3:下麵的程序演示了mb_convert_kana()函數。
PHP
<?php 
    
// Input array of strings 
$strings =  
  ["Hello, world!",  
   "こんにちは、世界!", 
   "12345",  
   "Geeks for Geeks"]; 
$convertToFullWidth = true; 
  
// Loop through the array and  
// conditionally convert the strings 
foreach ($strings as $string) { 
    if ($convertToFullWidth) { 
        $converted = mb_convert_kana($string, "A", "UTF-8"); 
    } else { 
        $converted = $string; 
    } 
  
    // Output the converted string 
    echo $converted . "\n"; 
} 
?>輸出
Hello, world! こんにちは、世界! 12345 Geeks for Geeks
參考:https://www.php.net/manual/en/function.mb-convert-kana.php
相關用法
- PHP mb_convert_case()用法及代碼示例
 - PHP mb_convert_encoding()用法及代碼示例
 - PHP mb_convert_variables()用法及代碼示例
 - PHP mb_check_encoding()用法及代碼示例
 - PHP mb_chr()用法及代碼示例
 - PHP mb_strlen()用法及代碼示例
 - PHP mb_substr_count()用法及代碼示例
 - PHP mb_substr()用法及代碼示例
 - PHP mb_substitute_character()用法及代碼示例
 - PHP mb_detect_order()用法及代碼示例
 - PHP mb_strtolower()用法及代碼示例
 - PHP mb_strtoupper()用法及代碼示例
 - PHP mb_str_split()用法及代碼示例
 - PHP mb_ereg()用法及代碼示例
 - PHP mb_http_input()用法及代碼示例
 - PHP mb_parse_str()用法及代碼示例
 - PHP mb_encode_numericentity()用法及代碼示例
 - PHP mb_encoding_aliases()用法及代碼示例
 - PHP mb_strrchr()用法及代碼示例
 - PHP mb_strimwidth()用法及代碼示例
 - PHP mb_ereg_search_regs()用法及代碼示例
 - PHP mb_ereg_search_init()用法及代碼示例
 - PHP mb_stristr()用法及代碼示例
 - PHP mb_ereg_search_pos()用法及代碼示例
 - PHP mb_split()用法及代碼示例
 
注:本文由純淨天空篩選整理自neeraj3304大神的英文原創作品 PHP mb_convert_kana() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
