I have a html form, where the user can write his / her own last name and send it to an php file, which checks if all is correct.
Now I would like to make an auto correction, for this case:
Last name: maX-poWEer
this should be corrected as follows
Max-Power
the first letters should be allways uppercase, and the others should be lowercase:
strtolower("maX-poWEer");
New Result:
max-power
But how can I realize the first letters of each name as uppercases? ucwords() doenst work in this case
CodePudding user response:
Use the mb_convert_case() function, this function can handle utf-8 characters, which is useful when dealing with international names.
$name = "maX-poWEer";
$formatted_name = mb_convert_case($name, MB_CASE_TITLE, "UTF-8");
echo $formatted_name; // Output: "Max-Poweer"