PHP 中的 ctype_alpha() 函數用於檢查給定字符串的所有字符是否為字母。如果所有字符都是字母,則返回 True 否則返回 False。
用法:
ctype_alpha($text)
使用的參數:
- $text:-它是一個強製參數,用於指定字符串。
返回值:
如果字符串的所有字符都是字母,則返回 True,失敗時返回 False。
例子:
Input :GeeksforGeeks Output:Yes Explanation:String (GeeksforGeeks) contains only alphabets Input :GFG-GCET-2018 Output:No Explanation:String contains Integer and special characters. Note:Except string ,if you input anything then it will return FALSE.
以下示例程序旨在說明 ctype_alpha() 函數。
節目:1
<?php
// PHP program to check given string is
// all characters -alphabetic
$string = 'GeeksforGeeks';
if ( ctype_alpha($string))
echo "Yes\n";
else
echo "No\n";
?>
輸出:
Yes
節目:2驅動代碼 ctype_alpha() 函數,其中輸入包含整數和特殊字符的字符串數組。
<?php
// PHP program to check given string is
// all characters are alphabetic
$strings = array(
'GFG',
'GFG space',
'@@##-- /',
'789543',
'\n'
);
// Checking above given strings
// by used of ctype_alpha() function .
foreach ($strings as $test) {
if (ctype_alpha($test))
echo "Yes\n";
else
echo "No\n";
}
?>
輸出:
Yes No No No No
相關文章: PHP | ctype_alnum()(檢查字母數字)
參考:
http://php.net/manual/en/function.ctype-alpha.php
相關用法
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | ctype_alpha() (Checks for alphabetic value)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。