How to determine whether a string is all lowercase in php

藏色散人
Release: 2023-04-04 16:18:01
Original
3795 people have browsed it

php determines whether the string is all lowercase. We can achieve this through PHP loop statements and the ord function. The ord function converts the first byte of the string to a value between 0-255.

How to determine whether a string is all lowercase in php

The code example is as follows:

<?php
function is_str_lowercase($str1)
{
    for ($sc = 0; $sc < strlen($str1); $sc++) {
        if (ord($str1[$sc]) >= ord(&#39;A&#39;) &&
            ord($str1[$sc]) <= ord(&#39;Z&#39;)) {
            return false;
        }
    }
    return true;
}
var_dump(is_str_lowercase(&#39;abc def ghi&#39;));
var_dump(is_str_lowercase(&#39;abc dEf ghi&#39;));
Copy after login

Here we create an is_str_lowercase function and test to determine the two strings "abc def ghi" and "abc dEf ghi" is all lowercase.

The judgment result is as follows:

How to determine whether a string is all lowercase in php

#The ord function means that the first byte of the string is converted to a value between 0-255.

Syntax description:

int ord ( string $string )
Copy after login

The first byte of parsed string binary value is an unsigned integer type ranging from 0 to 255. ,

string represents a character. Returns an integer value 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 article is an introduction to the method of PHP to determine whether a string is all lowercase. It is also very simple. I hope it will be helpful to friends in need!

The above is the detailed content of How to determine whether a string is all lowercase in php. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!