PHP mb_convert_kana() Function
Last Updated :
28 Sep, 2023
The mb_convert_kana() is an inbuilt function in PHP that is used to convert text into full-width and half-width.
Syntax:
mb_convert_kana($string, $mode, $encoding) : string
Parameters:
This function accepts three parameters that are described below.
- $string: This is the string that we want to convert using this function.
- $mode: This parameter specifies the different conversion options.
- $encoding: This parameter is optional. If you do not specify the encoding then It will use mb_internal_encoding() function encoding.
Return Value:
This mb_convert_kana() function returns the converted string.
Program 1: The following program demonstrates the mb_convert_kana() function.
PHP
<?php
$input = "Hello, world!" ;
$converted = mb_convert_kana( $input , "A" , "UTF-8" );
echo $converted ;
?>
|
Program 2: The following program demonstrates the mb_convert_kana() function.
PHP
<?php
$input = "12345" ;
$convertToFullWidth = true;
if ( $convertToFullWidth ) {
$converted = mb_convert_kana( $input , "N" , "UTF-8" );
} else {
$converted = $input ;
}
echo $converted ;
?>
|
Program 3: The following program demonstrates the mb_convert_kana() function.
PHP
<?php
$strings =
[ "Hello, world!" ,
"こんにちは、世界!" ,
"12345" ,
"Geeks for Geeks" ];
$convertToFullWidth = true;
foreach ( $strings as $string ) {
if ( $convertToFullWidth ) {
$converted = mb_convert_kana( $string , "A" , "UTF-8" );
} else {
$converted = $string ;
}
echo $converted . "\n" ;
}
?>
|
Output
Hello, world!
こんにちは、世界!
12345
Geeks for Geeks
Reference: https://www.php.net/manual/en/function.mb-convert-kana.php
Share your thoughts in the comments
Please Login to comment...