There is a single, native function that performs title-casing and is multibyte-safe. This is a very tidy solution because you don't need to prepare the string to be all lowercase before making the leading letter of all words uppercase.
Code: (Demo)
$string = "OH HeLlo world, it'S \"NiCE\" 'to' sEe you!";
echo mb_convert_case($string, MB_CASE_TITLE, 'UTF-8');
Output:
Oh Hello World, It's "Nice" 'To' See You!
The above demonstrates that the coment at https://www.php.net/manual/en/function.mb-convert-case.php#119629 is incorrect about the behavior relating to double-quote wtapped words.
Also, in Laravel, there is a helper method that can be mentioned: title()
.
use Illuminate\Support\Str;
$converted = Str::of('a nice title uses the correct case')->title();
// A Nice Title Uses The Correct Case
Source: https://laravel.com/docs/8.x/helpers#method-fluent-str-title