如何判断字符串是否为纯字母
Posted void9main
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何判断字符串是否为纯字母相关的知识,希望对你有一定的参考价值。
function checkStrIsLetter($str){ $letteraArr = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"); $letterAArr = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," "); //字母表 $letter = array_merge($letteraArr,$letterAArr); //分割字符 $strArr = str_split($str); //循环判断 if(!empty($strArr)){ foreach($strArr as $key=>$val){ if(!in_array($val,$letter)){ return "no"; exit; } } }else{ return "no"; } return "yes"; }
以上是关于如何判断字符串是否为纯字母的主要内容,如果未能解决你的问题,请参考以下文章