PHP: Check if Start of each word in a sentence is uppercase or any part of a word is UPPERCASE

When working with strings, occasionally we would want to check if any part of a word is uppercase or start of a word is an uppercase letter. This post provide a generic function that can be extended to match your needs.

For this post I will use the string below as my reference string

Now let’s define our function that precisely checks a word for an Uppercase regardless of its position

preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred.

Now let’s modify above function just to check if the first character is an Uppercase letter

Now let’s utilise the function we wrote above

I hope that in someway will be helpful to you, If you come across better method, I would like to know that,




VN:R_U [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:R_U [1.9.22_1171]
Rating: 0 (from 0 votes)

Leave a Reply