ctype_alpha() 函數(shù)檢測字符串中所有字符是否都為字母
ctype_alpha ( $text );
它檢查提供的字符串,文本中的所有字符是否都是字母。
| 序號 | 參數(shù)及說明 |
|---|---|
| 1 | text(必需) 要測試的字符串。 |
如果在當前語言環(huán)境中 text 里的每個字符都是一個字母,那么就返回TRUE,反之則返回FALSE。
檢測數(shù)組元素是否全是由字母組成。
<?php
$strings = array('example', 'example1234');
foreach ($strings as $test) {
if (ctype_alpha($test)) {
echo "$test 全部是字母。\n";
}else {
echo "$test 不全是字母。 \n";
}
}
?>測試看看?/?輸出結(jié)果:
example 全部是字母。 example1234 不全是字母。