HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

strcspn

Description

The strcspn of String for PHP find length of initial segment not matching mask.

Syntax

strcspn(
    string $string,
    string $characters,
    int $offset = 0,
    ?int $length = null
): int

Parameters

string

The string to examine.

characters

The string containing every disallowed character.

offset

The position in string to start searching.

If offset is given and is non-negative, then strcspn() will begin examining string at the offset'th position. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.

If offset is given and is negative, then strcspn() will begin examining string at the offset'th position from the end of string.

length

The length of the segment from string to examine.

If length is given and is non-negative, then string will be examined for length characters after the starting position.

If length is given and is negative, then string will be examined from the starting position up to length characters from the end of string.

Return

Returns the length of the initial segment of string which consists entirely of characters not in characters.

NOTE: When a start parameter is set, the returned length is counted starting from this position, not from the beginning of string.

Examples

1 · string characters

<?

$string = 'abcdefghijklmnopqrstu';
$characters = 'no';

$return = strcspn($string, $characters);

echo $return;
13

2 · offset · negative

<?

$string = 'abcdefghijklmnopqrstu';
$characters = 'no';
$offset = -10;

$return = strcspn($string, $characters, $offset);

echo $return;
2

3 · offset · non-negative

<?

$string = 'abcdefghijklmnopqrstu';
$characters = 'no';
$offset = 10;

$return = strcspn($string, $characters, $offset);

echo $return;
3

4 · length · negative

<?

$string = 'abcdefghijklmnopqrstu';
$characters = 'no';
$offset = 10;
$length = -10;

$return = strcspn($string, $characters, $offset, $length);

echo $return;
1

5 · length · non-negative

<?

$string = 'abcdefghijklmnopqrstu';
$characters = 'no';
$offset = 10;
$length = 10;

$return = strcspn($string, $characters, $offset, $length);

echo $return;
3