Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

ฟังก์ชัน ctype_upper() ใน PHP

คำอธิบาย

ฟังก์ชัน ctype_upper() ตรวจสอบว่าตัวอักษรทุกตัวในสตริงเป็นตัวพิมพ์ใหญ่ (uppercase) ทั้งหมดหรือไม่

รูปแบบการใช้งาน (Syntax)

ctype_upper(str)

พารามิเตอร์

  • str — สตริงที่ต้องการตรวจสอบ

ค่าที่คืนกลับ

คืนค่า TRUE หากทุกตัวอักษรเป็นตัวพิมพ์ใหญ่ หรือ FALSE หากไม่ใช่

ตัวอย่างการใช้งาน

<?php
$arr = array('HELLO', 'Hello', 'THAILAND', '123ABC');
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";
    }
}
?>

ผลลัพธ์

HELLO has all uppercase letters.
Hello does not have all uppercase letters.
THAILAND has all uppercase letters.
123ABC does not have all uppercase letters.

ตัวอย่างเพิ่มเติม

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

ผลลัพธ์

Word has all uppercase characters!