ucwords that works also with apices: '
for example: "aquila d'abruzzo" became "Aquila d'Abruzzo"
The second part after the // comment can removed! Is optimized for italian language (leave lowercase articles, prepositions, conjunctions) but easily changeable. Notice che "'s"!! for example "hotel 2000's" becames "Hotel 2000's".
function my_ucwords($s)
{
$a=strtolower($s);
$s=ucfirst($a);
for($x=0; $x<strlen($s)-1; $x++)
if(!ctype_alpha($s[$x])) $s[$x+1]=strtoupper($s[$x+1]);
//Lascia minuscoli articoli, preposizioni, congiunzioni
$minuscole=array("il", "lo", "la", "i", "gli", "le", //ARTICOLI DETERMINATIVI
"un", "uno", "una", //ARTICOLI INDETERMINATIVI
"e", "d", "l", "s", "un", //CONGIUNZIONI e CONTRATTI
"di", "a", "da", "in", "con", "su", "per", "tra", "fra", //PREPOSIZIONI SEMPLICI
"del", "dello", "della", "dei", "degli", "delle", //PREPOSIZIONI ARTICOLATE
"a", "al", "allo", "alla", "ai", "agli", "alle",
"da", "dal", "dallo", "dalla", "dai", "dagli", "dalle",
"in", "nel", "nello", "nella", "nei", "negli", "nelle",
"con", "col", "collo", "colla", "coi", "cogli", "colle",
"su", "sul", "sullo", "sulla", "sui", "sugli", "sulle",
"per", "pel", "pei");
foreach($minuscole as $value)
{
$pos=strpos($a, $value);
if( ( $pos>0 && $pos<strlen($s)-1 && !ctype_alpha($a[$pos-1]) && !ctype_alpha($a[$pos+1]) ) //CARATTERE IN MEZZO
|| ( $pos==strlen($s)-1 && !ctype_alpha($a[$pos-1]) ) ) //CASO PARTICOLARE: carattere in fondo. x es: "hotel 2000's"
$s[$pos]=strtolower($s[$pos]);
}
return $s;
}
function my_ucwords_essential($s)
{
$a=strtolower($s);
$s=ucfirst($a);
for($x=0; $x<strlen($s)-1; $x++)
if(!ctype_alpha($s[$x])) $s[$x+1]=strtoupper($s[$x+1]);
return $s;
}
Can be rewritten better, I Know