Converting Letters to Lowercase in PHP
Converting Letters to Lowercase in PHP
Sometimes, when coding a website with PHP, it may be necessary for all characters to be lowercase. This system feature can be used for websites with usernames, such as Twitter or Instagram, to ensure that all usernames are entirely lowercase and that each user can have a unique username. If you want to convert uppercase characters to lowercase for such a system or for any other purpose on your site, it's very simple. In this article, I will explain two different ways to convert uppercase letters to lowercase.
STRTOLOWER(); : You can convert letters to lowercase using the strtolower(); function. Of course, it cannot fully convert Turkish characters and can sometimes even throw errors, but still, let me show you how to use it.
$buyukkelime = "URHOBA.NET i ZiYaRet Ediyorum.";abc Function : As a second method, we can write a function to convert letters to lowercase smoothly.
$kelimekucult = strtolower($buyukkelime);
echo $kelimekucult;
the output you get from this code will be;
"urhoba.net i ziyaret ediyorum."
function abc($kucukkelime)You can apply such a function for the entire alphabet and use it to convert letters to lowercase without any issues.
{
$buyuk=array("A","B","C","Ç","D");
$kucuk=array("a","b","c","ç","d");
$kucukkelime=str_replace($buyuk,$kucuk,$kucukkelime);
return $kucukkelime;
}
Usage of this function;
$buyukkelime = "ABCÇD";Now that I have given the example, I am ending this article here. If you have any questions or things you are curious about, you can ask me in the comments.
$kucukkelime_a = abc($buyukkelime);
echo $kucukkelime_a;
When we run this function, its output will be "abcçd".


Yorum Gönder