Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

Hàm ctype_space() trong PHP

Mô tả

Hàm ctype_space() kiểm tra xem chuỗi có chỉ chứa ký tự khoảng trắng (space, tab, vertical tab, line feed, carriage return, form feed) hay không. Trả về TRUE nếu mọi ký tự tạo khoảng trắng, FALSE ngược lại.

Cú pháp

ctype_space(str)

Tham số

  • str − Chuỗi cần kiểm tra.

Giá trị trả về

Trả về TRUE nếu mọi ký tự là khoảng trắng, FALSE ngược lại.

Ví dụ

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

Kết quả

consists of all whitespace characters.
\test123 does not have all whitespace characters.

Ví dụ khác

<?php
$str = " ";
if (ctype_space($str)) echo "Whitespace!! \n";
else echo "No Whitespace character! \n";
?>

Kết quả

Whitespace!!