Hướng dẫn check uppercase php - kiểm tra chữ hoa php

(Php 4> = 4.0.4, Php 5, Php 7, Php 8)

Nội dung chính ShowShow

  • Sự mô tả
  • Thông số
  • Trả về giá trị
  • Làm thế nào để bạn kiểm tra xem một ký tự là chữ hoa?
  • Làm thế nào để bạn kiểm tra xem một ký tự trong chuỗi là chữ hoa?
  • Làm thế nào tôi có thể bán chữ hoa trong PHP?
  • Làm thế nào để bạn kiểm tra xem một chuỗi là tất cả các chữ thường?

CTYPE_UPPER - Kiểm tra (các) ký tự chữ hoa — Check for uppercase character(s)Check for uppercase character(s)

Sự mô tả

Thông số(mixed

echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
4): bool

Thông số

Trả về giá trị

Làm thế nào để bạn kiểm tra xem một ký tự là chữ hoa?

Làm thế nào để bạn kiểm tra xem một ký tự trong chuỗi là chữ hoa?:

Làm thế nào tôi có thể bán chữ hoa trong PHP?int between -128 and 255 inclusive is provided, it is interpreted as the ASCII value of a single character (negative values have 256 added in order to allow characters in the Extended ASCII range). Any other integer is interpreted as a string containing the decimal digits of the integer.

Làm thế nào để bạn kiểm tra xem một chuỗi là tất cả các chữ thường?

CTYPE_UPPER - Kiểm tra (các) ký tự chữ hoa — Check for uppercase character(s)string or an explicit call to chr() should be made.

Trả về giá trị

Làm thế nào để bạn kiểm tra xem một ký tự là chữ hoa?

Làm thế nào để bạn kiểm tra xem một ký tự trong chuỗi là chữ hoa?
echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
7
if every character in
echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
6 is an uppercase letter in the current locale. When called with an empty string the result will always be
echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
0
.

Làm thế nào tôi có thể bán chữ hoa trong PHP?

Làm thế nào để bạn kiểm tra xem một chuỗi là tất cả các chữ thường?ctype_upper() example (using the default locale)

echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
1

CTYPE_UPPER - Kiểm tra (các) ký tự chữ hoa — Check for uppercase character(s)

The string AKLWC139 does not consist of all uppercase letters.
The string LMNSDO consists of all uppercase letters.
The string akwSKWsm does not consist of all uppercase letters.

ctype_upper (hỗn hợp echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower'; 4): bool(mixed echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower'; 4): bool

  • echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
    
    6
  • Chuỗi được kiểm tra.
  • Ghi chú::

Nếu bao gồm một int giữa -128 và 255, nó được hiểu là giá trị ASCII của một ký tự duy nhất (giá trị âm có 256 được thêm vào để cho phép các ký tự trong phạm vi ASCII mở rộng). Bất kỳ số nguyên nào khác được hiểu là một chuỗi chứa các chữ số thập phân của số nguyên.int between -128 and 255 inclusive is provided, it is interpreted as the ASCII value of a single character (negative values have 256 added in order to allow characters in the Extended ASCII range). Any other integer is interpreted as a string containing the decimal digits of the integer.

Cảnh báo

Kể từ Php 8.1.0, việc chuyển một đối số không chuỗi được không phản đối. Trong tương lai, đối số sẽ được hiểu là một chuỗi thay vì một codepoint ASCII. Tùy thuộc vào hành vi dự định, đối số nên được chuyển vào chuỗi hoặc một cuộc gọi rõ ràng đến chr () nên được thực hiện.string or an explicit call to chr() should be made.

~      # starting pattern delimiter 
^      #match from the start of the input string
\p{Lu} #match exactly one uppercase letter (unicode safe)
~      #ending pattern delimiter 
u      #enable unicode matching

Trả về

echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
7 nếu mọi ký tự trong
echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
6 là một chữ cái viết hoa trong ngôn ngữ hiện tại. Khi được gọi với một chuỗi trống, kết quả sẽ luôn là

echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
0.
echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
7 if every character in
echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
6 is an uppercase letter in the current locale. When called with an empty string the result will always be
echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
0.

Ví dụ

$tests = ['âa', 'Bbbbb', 'Éé', 'iou', 'Δδ'];

foreach ($tests as $test) {
    echo "\n{$test}:";
    echo "\n\tPREG:  " , preg_match('~^\p{Lu}~u', $test)      ? 'upper' : 'lower';
    echo "\n\tCTYPE: " , ctype_upper(mb_substr($test, 0, 1))  ? 'upper' : 'lower';
    echo "\n\t< a:   " , mb_substr($test, 0, 1) < 'a'         ? 'upper' : 'lower';

    $chr = mb_substr ($test, 0, 1, "UTF-8");
    echo "\n\tMB:    " , mb_strtoupper($chr, "UTF-8") == $chr ? 'upper' : 'lower';
}

Output:

echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
0

Ví dụ #1 ví dụ CTYPE_UPPER () (sử dụng locale mặc định)ctype_upper() example (using the default locale)


Ví dụ trên sẽ xuất ra:

Xem thêm

CTYPE_ALPHA () - Kiểm tra (các) ký tự chữ cái

  • ctype_lower () - Kiểm tra (các) ký tự chữ thường

setlocale () - Đặt thông tin địa phương

Theo ý kiến ​​của tôi, việc thực hiện cuộc gọi

https://www.fileformat.info/info/unicode/category/Nl/list.htm

Ví dụ

echo preg_match('~^\p{Lu}~u', $string) ? 'upper' : 'lower';
3

Làm thế nào để bạn kiểm tra xem một ký tự là chữ hoa?

Làm thế nào để bạn kiểm tra xem một ký tự trong chuỗi là chữ hoa?If the ASCII value lies in the range of [65, 90], then it is an uppercase letter. If the ASCII value lies in the range of [97, 122], then it is a lowercase letter.

Làm thế nào để bạn kiểm tra xem một ký tự trong chuỗi là chữ hoa?

Làm thế nào tôi có thể bán chữ hoa trong PHP?use the toUpperCase() method to convert the letter to uppercase and compare it to itself. If the comparison returns true , then the letter is uppercase, otherwise it's lowercase.

Làm thế nào tôi có thể bán chữ hoa trong PHP?

Làm thế nào để bạn kiểm tra xem một chuỗi là tất cả các chữ thường?strtoupper() function converts a string to uppercase. Note: This function is binary-safe. Related functions: strtolower() - converts a string to lowercase.

Làm thế nào để bạn kiểm tra xem một chuỗi là tất cả các chữ thường?

CTYPE_UPPER - Kiểm tra (các) ký tự chữ hoa — Check for uppercase character(s)islower() method returns True if all characters in the string are lowercase, otherwise, returns “False”. It returns “True” for whitespaces but if there is only whitespace in the string then returns “False”.