See what portion of a string is composed only of a given set of characters : strcspn « String « PHP






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");
?>
           
       








Related examples in the same category

1.strcspn($password, '1234567890')
2.strspn: Find length of initial segment matching mask
3.strcspn Demo