|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24367 strspn('rRc', 'R') returns 0
Submitted: 2003-06-27 15:21 UTC Modified: 2003-06-30 04:51 UTC
From: php at projectjj dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.3.2 OS: Windows 2k SP3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: php at projectjj dot com
New email:
PHP Version: OS:


 [2003-06-27 15:21 UTC] php at projectjj dot com
echo strspn('rRc', 'R'); // returns 0
echo strspn('Rrc', 'R'); // returns 1

Shouldn't both of these return 1?

Reproduce code:
echo strspn('rRc', 'R');

Expected result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-27 17:36 UTC] marcot at tabini dot ca
No, because strspn is case-sensitive. In the first instance, there is no initial string that contains characters from your second parameter (the string begins with 'r', which doesn't match any of the characters in 'R'). In the second case, the first character of 'Rrc' contains characters from 'R', and therefore the function returns 1.
 [2003-06-27 17:45 UTC]
It works exactly the same as the libc counterpart,
that's the expected way. Not bug.

 [2003-06-27 19:05 UTC] php at projectjj dot com
I did expect it to be case-sensitive, but by your description that means it will only search from the start of the string.
A matching substring does not count.

From the manual:
"strspn --  Find length of initial segment matching mask"
The use of 'segment' made me think otherwise.

Perhaps a re-wording is needed...
 [2003-06-30 04:51 UTC]
What about "initial segment" do you find unclear?  Why would you think the use of "segment" in any way contradicts the use of "initial"?  I cannot think of any way of rewording this that would be appreciably clearer.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Sep 23 13:01:24 2023 UTC