note 87704 deleted from function.mb-convert-case by cmb
| From: | cmb@php.net | Date: | Fri, 22 Jul 2016 18:13:23 +0000 |
| Subject: | note 87704 deleted from function.mb-convert-case by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206078@lists.php.net to get a copy of this message | ||
Note Submitter: Justin
----
Retouching Alex's example so it works:
function titleCase($string, $exceptions = array('to', 'a', 'the',
'of', 'by', 'and', 'with', 'UI',
'V','X')) {
$words = explode(" ", $string);
$newwords = array();
foreach ($words as $word)
{
if (!in_array($word, $exceptions)) {
$word = strtolower($word);
$word = ucfirst($word);
}
array_push($newwords, $word);
}
return join(" ", $newwords);
}
It doesn't work for Irish names, etc. So keep that in mind.