i was trying to execute the following code
$string ='mynameisjenson';
echo strcspn( $string,'j',11);
the ouput am getting is 3 but really don't know how is gets 3.could any one please explain this
i was trying to execute the following code
$string ='mynameisjenson';
echo strcspn( $string,'j',11);
the ouput am getting is 3 but really don't know how is gets 3.could any one please explain this
The start
parameter tells strcspn()
to start looking at that position in the string, instead of starting at the beginning of the string.
strcspn($string, 'j', 11)
is equivalent to
strcspn(substr($string, 11), 'j')
Position 11 in your string is the s
character, so it's doing:
strcspn('son', 'j');
Since there's no j
in that part of the string, it returns 3.