- 6 years ago
- Zaid Bin Khalid
- 14,971 Views
-
8
Yesterday, I experience with Japanese characters not convert into uppercase or lowercase with PHP strtoupper() and strtolower() functions. So in this tutorial, I am going to share with you how you can change any kind of string with PHP.
If you have a simple string then you can use a strtoupper function to convert that string into uppercase see below code.
English character convert into upper and lower case.
<?php
$string = 'hi, jack i live in this world.';
print strtoupper($string);
//Output will be
HI, JACK I LIVE IN THIS WORLD.
$string = 'HI, JACK I LIVE IN THIS WORLD.';
print strtolower($string);
//Output will be
hi, jack i live in this world.
?>
How to convert other languages string into upper or lower case?
If you have mixed characters like “業務 Operation” and “管理部 Admin”. And any other language characters like “Τάχιστη αλώπηξ” then you can use the below function to convert into uppercase characters.
mb_strtoupper ( string $str [, string $encoding = mb_internal_encoding() ] ) : string
For lowercase you can use below function.
mb_strtolower ( string $str [, string $encoding = mb_internal_encoding() ] ) : string
Examples to change other languages characters into upper and lower case.
<?php
$str = "Τάχιστη αλώπηξ";
print $str = mb_strtolower($str, 'UTF-8');
//Output will be
τάχιστη αλώπηξ
$string = "業務 Operation 管理部 Admin";
print $str = mb_strtolower($string, 'UTF-8');
//Output will be
業務 OPERATION 管理部 ADMIN
?>
- 6 years ago
- Zaid Bin Khalid
- 14,971 Views
-
8