How to Convert a String to Uppercase Using ORD() Function in PHP?

Here is an example how to convert a string "Kolkata" to uppercase "KOLKATA" using ord() function in PHP.

$a{$i}=chr(ord($a{$i})-32);//here ord($a{$i})will return the ASCII value of ith character, and chr(ord($a{$i})-32)will return the character in UPPERCASE from an ASCII value.
//we know that the ASCII difference between the lowercase character and uppercase letter is 32.
echo "The string is in Uppercase:-"."<br>";
echo $a{$i};


Output: The string is in Uppercase:-

See also:

Leave a Comment