How to check if a string contain only letters and spaces in PHP

1 Answer

0 votes
$string ='PHP Java C';

if (ctype_alpha(str_replace(' ', '', $string)) === false) {
    echo "no";
}
else {
    echo "yes";
}


        
/*
run:
             
yes
      
*/

 



answered Dec 17, 2023 by avibootz
...