note 69544 added to function.ucwords

From: Date: Sat, 09 Sep 2006 16:35:21 +0000
Subject: note 69544 added to function.ucwords
Groups: php.notes 
Request: Send a blank email to php-notes+get-116960@lists.php.net to get a copy of this message
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 ---- Server IP: 213.92.11.19 Probable Submitter: 151.44.131.212 ---- Manual Page -- http://www.php.net/manual/en/function.ucwords.php Edit -- https://master.php.net/note/edit/69544 Del: integrated -- https://master.php.net/note/delete/69544/integrated Del: useless -- https://master.php.net/note/delete/69544/useless Del: bad code -- https://master.php.net/note/delete/69544/bad+code Del: spam -- https://master.php.net/note/delete/69544/spam Del: non-english -- https://master.php.net/note/delete/69544/non-english Del: in docs -- https://master.php.net/note/delete/69544/in+docs Del: other reasons-- https://master.php.net/note/delete/69544 Reject -- https://master.php.net/note/reject/69544 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116960) next »