คำอธิบาย
ฟังก์ชัน ctype_alnum() ตรวจสอบว่าตัวอักษรทุกตัวในสตริงเป็นตัวอักษรหรือตัวเลข (alphanumeric) ทั้งหมดหรือไม่
รูปแบบการใช้งาน (Syntax)
ctype_alnum(str)
พารามิเตอร์
- str — สตริงที่ต้องการตรวจสอบ
ค่าที่คืนกลับ
คืนค่า TRUE หากทุกตัวอักษรเป็นตัวอักษรหรือตัวเลข หรือ FALSE หากไม่ใช่
ตัวอย่างการใช้งาน
<?php
$str = array('hello123', 'hello!', 'THAI2024', 'test@mail');
foreach ($str as $a) {
if (ctype_alnum($a)) {
echo "$a consists of all letters or digits.\n";
} else {
echo "$a does not have all letters or digits.\n";
}
}
?>
ผลลัพธ์
hello123 consists of all letters or digits. hello! does not have all letters or digits. THAI2024 consists of all letters or digits. test@mail does not have all letters or digits.