Juris Juris - 2 months ago 13
PHP Question

Why should I use strtolower() rather than mb_strtolower()?

I understand the usage/behaviour difference between

strtolower()
and
mb_strtolower()
functions. And it has been asked before :)

But I don't understand - what is the current purpose of
strtolower
?

Is it available because of backwards compatibility? Or is there some use cases when
strtolower
is preferable? It seems that
mb_strtolower()
is safer and more versatile so I am tempted to use it everywhere...

Answer

Not really backward compatibility, but the ability to use code wihtout additionally loaded multibyte string extension. So a question of portability of the code.

strtolower() is always available. mb_strtolower() is only available if the additional mbstring module is loaded. The function overloading feature allows to use the "generic" call to strtolower() which will actually execute mb_strtolower() if configured such. So there actually is no need to explicitly code mb_strtolower() at all...

This makes code more portable, since it can run on systems with or without the mbstring extension.