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

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

คำอธิบาย

ฟังก์ชัน ctype_graph() ตรวจสอบว่าตัวอักษรทุกตัวในสตริงเป็นตัวอักษรที่พิมพ์ได้และมองเห็นได้ (visible) คือ ไม่รวมช่องว่าง (space) แต่มุ่งถึง tab, newline เป็นต้น

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

ctype_graph(str)

พารามิเตอร์

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

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

คืนค่า TRUE หากทุกตัวอักษรพิมพ์ได้และมองเห็นได้ (ไม่มี whitespace) หรือ FALSE หากไม่ใช่

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

<?php
$arr = array('hello', 'hello world', 'test123', "test\n");
foreach ($arr as $demo) {
    if (ctype_graph($demo)) {
        echo "$demo consists of all (visibly) printable characters\n";
    } else {
        echo "$demo does not have all (visibly) printable characters.\n";
    }
}
?>

ผลลัพธ์

hello consists of all (visibly) printable characters
hello world does not have all (visibly) printable characters.
test123 consists of all (visibly) printable characters
test
 does not have all (visibly) printable characters.