How do I use ucwords() to capitalize a letter after a slash?
I am trying to capitalize the T and P in "trailer/promo," but
ucwords() will only capitalize the T. Is there a way to do this?
Note: I cannot just manipulate the string to convert each / to a space, and back to a slash because I'll be running it on strings like "Music Video" which should not have slashes in them.
ucword will not do that for unless you manage to space the words out and join them together again after ucwording each word. Here is a simple example:
The code above simple makes an array from the string "trailer/promo" using the "/" as to separate words. And then run each word (using array_map() ) through ucwords().After each word is processed by ucwords, an array containing the processed values are joined together again using the same "/". All this is done is just one line.
ucwords - Manual, Returns a string with the first character of each word in str capitalized, if that " igua's code adds a backslash in front of the first single quote for me. and deleting blanks behind these chars, and using ucwords() in between: Should a word after a slash at the beginning of a sentence be capitalized? E.g. Risk/Issue management ; Risk/issue management; I would guess the first one is correct because "Issue" would be an alternative beginning due to the slash.
There are two methods you could use. The less-reliable, hope-there's-no-whitespace option:
str_replace(' ', '/', ucwords(str_replace('/', ' ', "trailer/promo,")));
And then probably a more robust method:
implode('/', array_map(ucwords, explode('/', "trailer/promo,")));
I'm sure I could probably think of some other. There's probably something like
filter_var() out there, buried somewhere.
Capitalize after slash at beginning (e.g. Risk/Issue management , For a sentence, only capitalise the first word: Risk/issue management is important because it will help you highlight For a title, capitalise all� // capitalize letter after certain name prefixes e.g 'Mc' Function to do what ucwords is intended to do - just correctly also for international char sets:
Thanks to the delimiter parameter of ucwords, since PHP 5.4.32 and 5.5.16, it is as simple as this:
MySQL: How to upper-case words, Script for UCWord and UCFirst for MySQL. Capitalize words and strings using a simple function/ [Forum] Capitalization after a slash in sentence case I haven't been able to find a specific rule for this one in CMOS. Can anyone help? What is the correct way to capitalize the following? Is the word directly after the slash capitalized (since it is an alternate way of beginning the sentence)? Or do you capitalize as if there were an "or" inserte
You can also do it using delimiter in php 7.2.24
$word = "White/white pearl and silver"; $result = ucwords(ucwords($word)), "/");
Result string will be "White/White Pearl And Silver"
In Laravel 5.7
PHP, Use regex to match the dot \. , optional space \s* and a letter \w . in PHP, You can use the PHP ucfirst() function to change the first character of a string to the word 'down' and hit the space bar, your two hyphens will change to an M hyphen. Don't capitalize the spelled-out form of an acronym unless it's a proper noun. When words are joined by a slash, capitalize the word after the slash if the word before the slash is capitalized. Examples Country/Region Turn on the On/Off toggle. For information on capitalization in hyphenated compound words see Hyphens.
PHP ucwords() Function, The ucwords() function converts the first character of each word in a string to uppercase. Note: This function is binary-safe. Related functions: ucfirst() - converts� …He provided the following data: The date was the 4th at a little after 5:00. …He provided the following data: the 4th of May at a little after 5:00. Capitalize the first word after a dash only when the word always has to be capped. (Do not cap for a complete sentence.) …I was going to see him — it was Friday, June 3 — to ask that
Slash. The slash ( / ), also known as the virgule, has several uses, most of which should be avoided in formal writing. Never use a backslash ( \ ) in place of a slash. Poetry. The one inarguably acceptable use of the slash in formal writing pertains to poetry. The slash, with one space on either side, indicates a line break.
Capitalization: First Word After a Colon. In British English, the first letter after a colon is capitalized only if it’s a proper noun or an acronym; in American English, the first word after a colon is sometimes capitalized if it begins a complete sentence.