PHP/String/strcspn
Версия от 10:37, 26 мая 2010; (обсуждение)
See what portion of a string is composed only of a given set of characters
<?
$twister = "Peter Piper picked a peck of pickled peppers";
$charset = "Peter picked a";
print("The segment matching "$charset" is " . strspn($twister, $charset) . " characters long");
?>
strcspn($password, "1234567890")
<?php
$password = "a12345";
if (strcspn($password, "1234567890") == 0) {
print "Password cannot consist solely of numbers! ";
}
?>
strspn: Find length of initial segment matching mask
<?php
$password = "3312345";
if (strspn($password, "1234567890") == strlen($password))
echo "The password cannot consist solely of numbers!";
?>