strcspn
strcspn
Find length of initial segment not matching mask
int **strcspn** string $string string $characters int $offset $length
Returns the length of the initial segment of
which does
contain any of the characters in .
stringnotcharacters
If and
are omitted, then all of will be
examined. If they are included, then the effect will be the same as
calling (see
for more information).
offset``length``string``strcspn(substr($string, $offset, $length), $characters)
stringThe string to examine.
charactersThe string containing every disallowed character.
offset
The position in to
start searching.
string
If is given and is non-negative,
then will begin
examining at
the 'th position. For instance, in
the string '', the character at
position is '', the
character at position is
'', and so forth.
`offset``strcspn``string``offset``abcdef``0``a``2``c`
If is given and is negative,
then will begin
examining at
the 'th position from the end
of .
`offset``strcspn``string``offset``string`
length
The length of the segment from
to examine.
string
If is given and is non-negative,
then will be examined
for characters after the starting
position.
`length``string``length`
If is given and is negative,
then will be examined from the
starting position up to
characters from the end of .
`length``string``length``string`
Returns the length of the initial segment of
which consists entirely of characters in .
stringnotcharacters
Opmerking: > When a parameter is set, the returned length is counted starting from this position, not from the beginning of .
offset``string
Voorbeeld: example
<?php
$a = strcspn('banana', 'a');
$b = strcspn('banana', 'abcd');
$c = strcspn('banana', 'z');
$d = strcspn('abcdhelloabcd', 'a', -9);
$e = strcspn('abcdhelloabcd', 'a', -9, -5);
var_dump($a);
var_dump($b);
var_dump($c);
var_dump($d);
var_dump($e);
?>
int(1)
int(0)
int(6)
int(5)
int(4)
strspn