использование заглавных букв — я ищу существующую функцию PHP, чтобы правильно использовать заглавные буквы

Я уверен, что кто-то решил эту проблему. У меня есть столбец названия должности в таблице. Я хочу правильно использовать названия должностей.

For example: computer and information research scientist
Should be:   Computer and Information Research Scientist

Заранее спасибо,
Брюс

-2

Решение

Похоже, вы ищете заглавный случай, я бы попробовал это:

function strtotitle($title)
// Converts $title to Title Case, and returns the result.
{
// Our array of 'small words' which shouldn't be capitalised if
// they aren't the first word. Add your own words to taste.
$smallwordsarray = array( 'of','a','the','and','an','or','nor','but','is','if','then','else','when', 'at','from','by','on','off','for','in','out','over','to','into','with' );

// Split the string into separate words
$words = explode(' ', $title);

foreach ($words as $key => $word)
{
// If this word is the first, or it's not one of our small words, capitalise it
// with ucwords().
if ($key == 0 or !in_array($word, $smallwordsarray))
$words[$key] = ucwords($word);
}

// Join the words back into a string
$newtitle = implode(' ', $words);

return $newtitle;
}

простой поиск в Google привел меня к этому на sitepoint.com

1

Другие решения

Я хотел бы поблагодарить Стюарта за то, что он указал мне правильное направление. Он предложил мне посмотреть здесь: http://php.net/manual/en/function.ucwords.php#112795
Это отличная отправная точка для меня.
Еще раз спасибо, Стюарт!
Брюс

-2