Questions tagged [ucfirst]

ucfirst, short for 'Upper Case First', is a function which replaces the first letter of words in a string by their uppercase equivalent.

ucfirst (short for Upper Case First is a function for making a string's first character uppercase. For more details, see the PHP manual page.

35 questions
47
votes
12 answers

Title case a string containing one or more last names while handling names with apostrophes

I want to standardize a user-supplied string. I'd like the first letter to be capitalized for the name and if they have entered two last names, then capitalize the first and second names. For example, if someone enters: marriedname maidenname It…
user1048676
  • 9,756
  • 26
  • 83
  • 120
21
votes
2 answers

Sublime Text - command to make first character uppercase

There are upper_case and lower_case commands: { "keys": ["ctrl+k", "ctrl+u"], "command": "upper_case" }, { "keys": ["ctrl+k", "ctrl+l"], "command": "lower_case" }, I'm searching for command to capitalize the first letter of string, which can be…
Limon Monte
  • 52,539
  • 45
  • 182
  • 213
9
votes
4 answers

Make string title case using ucfirst

I'm probably missing something really obvious. While converting a bunch of string before inserting them in a array I noticed some string where different among each other because of first char being uppercase or not. I decided then to use ucfirst to…
Fabio
  • 23,183
  • 12
  • 55
  • 64
8
votes
5 answers

How to make first letter of a word capital?

I have a word default and I want a php function to make only first letter capital. Can we do that. Please help me out as I am very new to php coding.
user690436
7
votes
1 answer

Truncating Chinese text

Our website is in Chinese and a part of the main page shows a list of other page titles at a maximum length of what works out as being called '26' (I assume this is using the English character count if the Chinese characters were written using…
JoeW
  • 578
  • 1
  • 10
  • 29
6
votes
3 answers

Make all words lowercase and the first letter of each word uppercase

I have a string with improper capitalization scattered like below: $str = "tHis iS a StRinG thAt NeEds ProPer CapiTilization"; $newStr = ucfirst($str); echo $newStr; How would I be able to capitalize the first letter of each word and lower case the…
HelloWorld
  • 335
  • 2
  • 7
5
votes
5 answers

Ucfirst doesnt work on non-english characters

I'm trying to make the first letter uppercase in a string. It works fine for english letters, but unfortunetely, it doesn't work on non-english chars, for example echo ucfirst("çağla"); What is the correct way to make ucfirst work properly on all…
user198989
  • 4,574
  • 19
  • 66
  • 95
2
votes
5 answers

Making first character of all sentences upper case

I have a function that is suppose to make the first character of all sentences uppercase, but for some reason, it's not doing it to the first character of the first sentence. Why is that happening, and how do I fix it?
jessica
  • 1,667
  • 1
  • 17
  • 35
2
votes
3 answers

Get, modify, then print post title in wordpress

Is there a way native way in wordpress to make uppercase the first letter of the first word of the scentence / the_title of the post? If not, how do I do it in php, while it is wrapped in a tag? Here is the full line of code.
gurung
  • 628
  • 2
  • 11
  • 33
2
votes
3 answers

ucfirst capitalizing the second letter when run at command line

I have a log method which saves to a file that is named the same as the script calling it, only with a capital first letter, which works sometimes, but other times capitalizes the second letter (I can't see any pattern as to when it does what but…
Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236
1
vote
2 answers

PHP error when using ucfirst() with variables

Im trying to display a country name from a database with first letter capitalised. For instance, if the country was Brazil, the database has it as 'brazil', and I would like it to be 'Brazil'. This is the code I have tried: ucfirst($name) =…
jahsss
  • 13
  • 2
1
vote
3 answers

Capitalizing words by uppercasing only the first letter

In Perl, there's the ucfirst function. Is it this the equivalent to this: sub uppercase { my ($W) = @_; $$W = uc(substr($$W,0,1)).substr($$W,1); } Does it matter across Perl version? Contextualizing the question,…
alvas
  • 115,346
  • 109
  • 446
  • 738
1
vote
1 answer

PHP - apply ucfirst() to first character that isn't HTML

I'm outputting a string assembled from a few different parts, and some of those parts may or may not contain some HTML. If I apply ucfirst() to the string and there's HTML before the text to be displayed then the text doesn't get proper…
nickfindley
  • 308
  • 1
  • 9
1
vote
4 answers

In paragraph making the first letter of every sentence uppercase?

I got this function from php.net for convert uppercase become lowercase in sentence case. function sentence_case($string) { $sentences = preg_split('/([.?!]+)/', $string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); $new_string = ''; …
v123shine
  • 13
  • 5
1
vote
1 answer

Capitalize after point and space only the next word after point ( maybe regex + ucfirst )

Capitalize after point and space only the next word after point, maybe using regex + ucfirst.. preg_match('/[\s\.][a-z]/' $theCode = str_replace(ucfirst..... In summary is to do uppercase only in the first letter after spaço + point, in all data of…
1
2 3