PHP » Strings » strcspn()

Syntax:
int strcspn(string s1, string s2)
s1
The string to be counted.
s2
Characters that count.

Checks character occurrences in a string.

This function is similar to strspn(), but strcspn() returns how far, as a number of characters, into the first string no characters from the second string appear.

Examples

Code:
<?php

$digits = implode(range(0, 9));
$passwd = "secret";

if (strcspn($passwd, $digits) == strlen($passwd)) {
   print "Password must contain digits also.";
} else {
   print "Password is legal";
}

?>
Output:
Password must contain digits also.
Explanation:

strcspn() is used to check that a password contains digits.

See Also: