Php/docs/function.ctype-space

提供:Dev Guides
< Php
移動先:案内検索

ctype_space

(PHP 4 >= 4.0.4, PHP 5, PHP 7)

ctype_space空白文字かどうか調べる


説明

ctype_space ( mixed $text ) : bool

与えられた文字列 text のすべての文字が 空白文字であるかどうかを調べます。


パラメータ

text

調べる文字列。

注意:

-128 から 255 までの int を渡すと、ひとつの文字の ASCII 値とみなします (負の値には 256 を足して、拡張 ASCII の範囲に収まるようにします)。 それ以外の整数値は、10 進数を含む文字列とみなします。


返り値

text のすべての文字がなんらかの空白文字を 生成する場合に true 、そうでない場合に false を返します。 空白文字には、タブ・垂直タブ・改行・復帰・フォームフィード文字も 含まれます。


例1 ctype_space() の例

<?php$strings = array(    'string1' => "\n\r\t",    'string2' => "\narf12",    'string3' => '\n\r\t' // 単一引用符に注意してください。);foreach ($strings as $name => $testcase) {    if (ctype_space($testcase)) {        echo "The string '$name' consists of whitespace characters only.\n";    } else {        echo "The string '$name' contains non-whitespace characters.\n";    }}?>

上の例の出力は以下となります。


The string 'string1' consists of whitespace characters only.
The string 'string2' contains non-whitespace characters.
The string 'string3' contains non-whitespace characters.

参考

  • ctype_cntrl() - 制御文字かどうかを調べる
  • ctype_graph() - 空白以外の印字可能な文字かどうかを調べる
  • ctype_punct() - 空白、英数字以外の出力可能な文字かどうかを調べる