note 102190 modified in function.strspn by danbrown
| From: | danbrown@php.net | Date: | Tue, 01 Feb 2011 21:00:56 +0000 |
| Subject: | note 102190 modified in function.strspn by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176573@lists.php.net to get a copy of this message | ||
very dificult to get from the definition directly, while i search for that,i came to know that
strspn() will tell you the length of a string consisting entirely of the set of characters in accept
set. That is, it starts walking down str until it finds a character that is not in the set (that is,
a character that is not to be accepted), and returns the length of the string so far.
and
strcspn() works much the same way, except that it walks down str until it finds a character in the
reject set (that is, a character that is to be rejected.) It then returns the length of the string
so far.
<?php
$acceptSet = "aeiou";
$rejectSet = "y";
$str1 ="a banana";
$str2 ="the bolivian navy on manuvers in the south pacific";
echo $n = strspn($str1,$acceptSet);// $n == 1, just "a"
echo $n = strcspn($str2,$rejectSet);// n = 16, "the bolivian nav"
?>
hope this example will help in understanding the concept of strspn() and strcspn().
--was--
very dificult to get from the definition directly, while i search for that,i came to know that
strspn() will tell you the length of a string consisting entirely of the set of characters in accept
set. That is, it starts walking down str until it finds a character that is not in the set (that is,
a character that is not to be accepted), and returns the length of the string so far.
and
strcspn() works much the same way, except that it walks down str until it finds a character in the
reject set (that is, a character that is to be rejected.) It then returns the length of the string
so far.
$acceptSet = "aeiou";
$rejectSet = "y";
$str1 ="a banana";
$str2 ="the bolivian navy on manuvers in the south pacific";
echo $n = strspn($str1,$acceptSet);// $n == 1, just "a"
echo $n = strcspn($str2,$rejectSet);// n = 16, "the bolivian nav"
hope this example will help in understanding the concept of strspn() and strcspn().
http://php.net/manual/en/function.strspn.php