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

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

คำอธิบาย

ฟังก์ชัน ctype_print() ตรวจสอบว่าตัวอักษรทุกตัวในสตริงเป็นตัวอักษรที่พิมพ์ได้ (printable) หรือไม่ รวมถึงตัวอักษร ช่องว่าง และเครื่องหมายวรรคตอน แต่ไม่รวม control characters

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

ctype_print(str)

พารามิเตอร์

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

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

คืนค่า TRUE หากทุกตัวอักษรพิมพ์ได้ หรือ FALSE หากมี control characters

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

<?php
$arr = array("hello\n", "world123", "test@#$");
foreach ($arr as $x) {
    if (ctype_print($x)) {
        echo "$x has all printable characters.\n";
    } else {
        echo "$x does not have all printable characters.\n";
    }
}
?>

ผลลัพธ์

hello
 does not have all printable characters.
world123 has all printable characters.
test@#$ has all printable characters.

หมายเหตุ: \n (newline) เป็น control character จึงคืนค่า FALSE