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 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!
Program 2: The following program demonstrates the mb_convert_kana() function.
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
Program 3: The following program demonstrates the mb_convert_kana() function.
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
Reference: https://www.php.net/manual/en/function.mb-convert-kana.php
