Encodera

Thanks for reading!

Donate to the site — we work hard for you.

How to convert a string to uppercase or lowercase

Short answer

Use the functions with the mb_ prefix — they work with any alphabet:

<?php
 
echo mb_strtoupper('привет, world'), "\n";
echo mb_strtolower('ПРИВЕТ, World');

Output:

ПРИВЕТ, WORLD
привет, world

Why not strtoupper()

The plain functions change ASCII letters only:

<?php
 
echo strtoupper('привет, world');

Output:

привет, WORLD

A capital first letter

For non-ASCII text the first letter is converted separately:

<?php
 
$text = 'привет';
 
echo mb_strtoupper(mb_substr($text, 0, 1)) . mb_substr($text, 1);

Output:

Привет

Functions used in this recipe

Thanks for reading!

Donate to the site — we work hard for you.