I have an array of people of which I want the first letter of each word to be capitalized, therefore I am using ucwords()
. The problem arises as you are acting as if you are using ucfirst()
.
Code:
foreach ($data['alumnos'] as &$alumno) {
var_dump($alumno['nombre_completo']);
$alumno['nombre_completo'] = ucwords(strtolower($alumno['nombre_completo']));
var_dump($alumno['nombre_completo']);
}
Departure:
string(29) "BARRIOS HERNANDEZ CHRISTIAN"
string(29) "Barrios hernandez christian"
string(32) "CASTAÑEDA PADILLA JUAN DIEGO"
string(32) "CastaÑeda padilla juan diego"
string(31) "CORONA VALADEZ CARLOS ALEXIS"
string(31) "Corona valadez carlos alexis"
string(31) "DE REZA VELEZ JESUS OSWALDO"
string(31) "De reza velez jesus oswaldo"
string(34) "ALTAMIRANO MORELOS DAN EMMANUEL"
string(34) "Altamirano morelos dan emmanuel"
string(34) "ALVARADO CONTRERAS JORGE CARLOS"
string(34) "Alvarado contreras jorge carlos"
Just convert the first letter as if it were ucfirst()
. In which part am I implementing it in the wrong way or where the problem arises.
It works fine for me when I do it directly in a single person arrangement.
Example:
$data['profesor']['nombre_completo'] = ucwords(strtolower($data['profesor']['nombre_completo']));
I was testing your code and I only changed it
ucwords
tomb_convert_case
, since the latter also transforms letters with accents and accents to lowercase letters like Ñ at once ; you can see your example running here with mb_convert_case , hopefully that's what you're looking for.Example of the mb_convert_case:
The mb_convert_case has 3 parameters:
1) str: The string to convert.
2) mode: The conversion mode. It can be MB_CASE_UPPER, MB_CASE_LOWER, or MB_CASE_TITLE.
3) encoding: The encoding parameter is the character encoding. If omitted, the internal character encoding value will be used.