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

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

คำอธิบาย

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

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

ctype_punct(str)

พารามิเตอร์

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

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

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

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

<?php
$srr = array('!@#$%', 'hello!', '*$()');
foreach ($srr as $d) {
    if (ctype_punct($d)) {
        echo "$d consists of all punctuation.\n";
    } else {
        echo "$d does not have all punctuation.\n";
    }
}
?>

ผลลัพธ์

!@#$% consists of all punctuation.
hello! does not have all punctuation.
*$() consists of all punctuation.