Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

Hàm ctype_upper() trong PHP

Mô tả

Hàm ctype_upper() kiểm tra xem chuỗi có chỉ chứa ký tự in hoa theo locale hiện tại hay không. Trả về TRUE nếu mọi ký tự là chữ in hoa, FALSE ngược lại.

Cú pháp

ctype_upper(str)

Tham số

  • str − Chuỗi cần kiểm tra.

Giá trị trả về

Trả về TRUE nếu mọi ký tự là chữ in hoa, FALSE ngược lại.

Ví dụ

<?php
$arr = array('9898jjhh', 'PQR', 'Amit');
foreach ($arr as $demo) {
    if (ctype_upper($demo)) {
        echo "$demo has all uppercase letters. \n";
    } else {
        echo "$demo does not have all uppercase letters. \n";
    }
}
?>

Kết quả

9898jjhh does not have all uppercase letters.
PQR has all uppercase letters.
Amit does not have all uppercase letters.

Ví dụ khác

<?php
$str = 'AUSTRALIA';
if (ctype_upper($str)) {
    echo "Word has all uppercase characters!\n";
} else {
    echo "Word does not have all uppercase characters!\n";
}
?>

Kết quả

Word has all uppercase characters!