note 102190 added to function.strspn
| From: | mrsohailkhan at gmail dot com | Date: | Tue, 01 Feb 2011 20:56:47 +0000 |
| Subject: | note 102190 added to function.strspn | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176572@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.
$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().
----
Server IP: 69.147.83.197
Probable Submitter: 115.186.139.179
----
Manual Page -- http://www.php.net/manual/en/function.strspn.php
Edit -- https://master.php.net/note/edit/102190
Del: integrated -- https://master.php.net/note/delete/102190/integrated
Del: useless -- https://master.php.net/note/delete/102190/useless
Del: bad code -- https://master.php.net/note/delete/102190/bad+code
Del: spam -- https://master.php.net/note/delete/102190/spam
Del: non-english -- https://master.php.net/note/delete/102190/non-english
Del: in docs -- https://master.php.net/note/delete/102190/in+docs
Del: other reasons-- https://master.php.net/note/delete/102190
Reject -- https://master.php.net/note/reject/102190
Search -- https://master.php.net/manage/user-notes.php