note 61563 deleted from function.mb-convert-case by cmb
| From: | cmb@php.net | Date: | Fri, 22 Jul 2016 18:13:26 +0000 |
| Subject: | note 61563 deleted from function.mb-convert-case by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206079@lists.php.net to get a copy of this message | ||
Note Submitter: alex at agileware dot net
----
This function is a bit more flexible than using mb_convert_case with MB_CASE_TITLE, because it lets
you add words whose case you don't want modified.
function title_case($string, $exceptions = array('to', 'a', 'the',
'of', 'I', 'II', 'III', 'IV', 'V',
'VI', 'VII', 'VIII', 'IX', 'X')) {
$words = split(" ", $string);
$newwords = array();
foreach ($words as $word)
{
if (!array_key_exists($word, $exceptions)) {
$word = strtolower($word);
$word = ucfirst($word);
}
array_push($newwords, $word);
}
return ucfirst(join(" ", $newwords));
}