Sunday, September 22, 2024
Google search engine
HomeLanguagesPHP mb_convert_kana() Function

PHP mb_convert_kana() Function

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;
?>


Output

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;
?>


Output

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";
}
?>


Output

Hello, world!
こんにちは、世界!
12345
Geeks for Geeks

Reference: https://www.php.net/manual/en/function.mb-convert-kana.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments