![]() ![]() We can now operate on each word separately. ![]() Here it would be equal to array(‘This’, ‘is’, ‘a’, ‘title’). $words becomes an array of strings, each string representing one word from the original $title. $words = explode(' ', 'this is a title') So if we split with a space character (‘ ‘), we can use explode to split our string into words. The explode function in PHP can be used to split any string into an array of strings, using a character as a split character. However, I’m no expert in English grammar so I’ll just call them ‘small words’. The words we should be concerned about are conjunctions (such as and, or), prepositions (in, on) and internal articles (the, a). The following mini-tutorial will provide a solution similar to the one I came up with for displaying thread titles in the SitePoint Forums’ Highlighted Forum Discussions.įirst, we’ll need a list of all the words which we don’t want to capitalise when they are not the first word. However, there exists in the standard PHP library no way of achieving Title Case, which involves capitalising all words except for small words (such as conjunctions) when they are not the first word. The PHP functions strtoupper and ucwords capitalise all characters in a string, and the first letter of every word in a string, respectively. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |