PHP checks whether the string contains uppercase characters, that is, whether the specified string is all lowercase. We can achieve this through for loops and strlen() and ord() functions.
Let’s take a look at specific code examples to introduce how PHP checks whether a string contains uppercase characters.
The code example is as follows:
<?php function is_str_lowercase($str1) { for ($sc = 0; $sc < strlen($str1); $sc++) { if (ord($str1[$sc]) >= ord('A') && ord($str1[$sc]) <= ord('Z')) { return false; } } return true; } var_dump(is_str_lowercase('abc def ghi')); var_dump(is_str_lowercase('abc dEf ghi'));
Here we create an is_str_lowercase method to determine whether the strings 'abc def ghi' and 'abc dEf ghi' are uppercase or all lowercase.
The output is as follows:
bool(true) bool(false)
Then returning true means that the string is all lowercase, returning false means that the string contains uppercase characters.
Required function:
ord() function Convert the first byte of the string to a value between 0-255
ord ( string $string ) : int
Parse string The first byte of the binary value is an unsigned integer type ranging from 0 to 255. If the string is a single-byte encoding such as ASCII, ISO-8859, Windows 1252, etc., it is equivalent to returning the position of the character in the character set encoding table. But please note that this function does not detect the encoding of the string, especially Unicode code points for multi-byte characters such as UTF-8 or UTF-16.
This function is the complementary function of chr() .
Parametersstring represents a character.
Return value: Return an integer value from 0 to 255.
strlen() function means getting the string length
strlen ( string $string ) : int
Returns the length of the given string string.
The parameter string represents the string whose length needs to be calculated.
Return value: If successful, the length of the string string is returned; if string is empty, 0 is returned.
This article is an introduction to the method of checking whether a string contains uppercase characters in PHP. It is simple and easy to understand. I hope it will be helpful to friends in need!
The above is the detailed content of PHP check if string contains uppercase characters. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software