How to check if a string contain only of 1 and 0 in PHP

1 Answer

0 votes
$str = "10100011101";

if (strspn($str , '01') == strlen($str)) {
    echo 'Yes';
} else {
    echo 'No';
}




/*
run:

Yes

*/

 



answered Apr 12, 2023 by avibootz
...