12
ucnatwords
ucnatwords
SYNOPSIS
ucnatwords($s)
DESCRIPTION
ucnatwords retourne la chaîne de caractères $s convertie en minuscules, sans accents, avec la première lettre de chaque mot en majuscule.
EXEMPLE
php > require 'library/ucnatwords.php';
php > var_dump(ucnatwords('aNNe-mARIE lEFÈVRE'));
string(18) "Anne-Marie Lefevre"
CODE
- require_once 'strflat.php';
- function ucnatwords($s) {
- // capitalize first letter in every word after removing accents
- return preg_replace_callback("#(^|[ '~-])(\w+)#", function($e) { return $e[1].strtoupper($e[2][0]).substr($e[2], 1); }, strtolower(strflat($s)));
- }
Commentaires