Capitalizing Letters with PHP
Capitalizing Letters with PHP
I previously wrote a post about lowercasing letters with PHP and in that post I talked about how we can lowercase letters.In this post, imagine you've designed a website and let's say this site is a blog design. On this blog you designed, you always want the posted titles to be written in uppercase letters, but users may post titles in lowercase. In such cases, we need to ensure that the system automatically converts titles to uppercase. Let's take a look at how we can capitalize letters with PHP.
STRTOUPPER(): In PHP you can use the strtoupper(); function to capitalize letters.
Of course, when you use strtoupper, you may face problems with Turkish characters in your text. If this is not important for you, you can use it.
Example Usage
$kelime = "küçük yazdım.";
$buyukkelime = strtoupper($kelime);
echo $buyukkelime; // When you write it this way, your letters will be output in uppercase.
Capitalizing Letters with a Function: In PHP, you can also do everything yourself. If you want it to work more smoothly and avoid problems with Turkish characters, you can write your own function.
Example Usage
function harfbuyut($kelime){
$buyuk=array("A","B","C","Ç","D");
$kucuk=array("a","b","c","ç","d");
$buyukkelime=str_replace($kucuk,$buyuk,$kelime);
return $buyukkelime;
}
With a function like this, you can capitalize letters.
Note: Since this is an example, I did not write all the letters. If you write all the letters in the alphabet in order, it will be valid for all letters.
So how will we use this function?
$kelime = "abcçd";
$buyult = harfbuyut($kelime);
echo $buyult; // The output will be "ABCÇD".
You can ask your questions about PHP in the comments.


Yorum Gönder