Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a String is ALL CAPS in PHP

Tags:

string

php

What's the best way to see if a string contains all capital letters? I still want the function to return true if the string also contains symbols or numbers.

like image 296
Kirk Ouimet Avatar asked Nov 18 '10 05:11

Kirk Ouimet


People also ask

How do you check if the first letter of a string is uppercase PHP?

“check if first letter is uppercase php” Code Answer's$bar = ucfirst(strtolower($bar)); // Hello world!

Is PHP a capital?

The strtoupper() function converts a string to uppercase. Note: This function is binary-safe. Related functions: strtolower() - converts a string to lowercase.

Is Lower Case PHP?

PHP | strtolower() FunctionThe strtolower() function is used to convert a string into lowercase. This function takes a string as parameter and converts all the uppercase english alphabets present in the string to lowercase. All other numeric characters or special characters in the string remains unchanged.

How do you check if a string contains a number in PHP?

PHP – How to check if String contains Number(s)?Iterate over the characters of the string, and for each character, use ctype_digit() function to check if the character is a digit or not. When you found a digit, you can break the loop and confirm that there is a number in the string.


2 Answers

Check whether strtoupper($str) == $str

To handle non-ascii use:

mb_strtoupper($str, 'utf-8') == $str

like image 92
Winston Ewert Avatar answered Oct 24 '22 18:10

Winston Ewert


ctype_upper(string $testString)

like image 25
jonathancardoso Avatar answered Oct 24 '22 19:10

jonathancardoso