PHP strspn() Function

PHP strspn() Function

The strspn() function of PHP finds the length of the initial segment of string that contains only characters from the mask parameter.

Syntax

strspn(string$subject,string$mask[,int$start[,int$length]]
)

Parameter

subject(required)- This parameter represents the input string.

mask(required)- This parameter specifies the characters to find.

start (optional)- It signifies the position in the string to start searching.

length(optional)- This parameter represents the length of the segment from subject to examine. If length is positive, then string will be examined for length characters after the starting position else for negative length the subject will be examined from the starting position.

Return

This function returns the length of the initial segment of subject only characters from the mask parameter.

Example 1

  

Output

String 1: Hello world!
String 2: PHPlleo
The strspn() function will return: 5 

Example 2

  

Output

 String 1: Hook
 String 2: o
 The returned value: int(0) 

Example 3

  

Output

String 1: Hook
String 2: o
The returned value: int(2) 

Example 4

  

Output

String 1: Hook
String 2: o
The returned value: int(2) 

Related Topics

PHP get_defined_vars() Function

PHP get_defined_vars() Function The get_defined_vars() function in PHP returns an array of all defined variables. It returns a multidimensional array containing a list of all defined variables. Syntax get_defined_vars ( void ) Parameter NA Return This function returns a multidimensional array containing a list...

1 minute read.

PHP array_diff_key () Function

PHP array_diff_key () Function The array_diff_key () Function in PHP compares the keys from array1 against the keys from arrays. It returns an array containing all the entries from array1 whose keys are absent from all other arrays. This function is like array_diff () except that...

1 minute read.

PHP strcmp() Function

PHP strcmp() Function The strcmp() function in PHP compares two strings. It is a binary-safe case-sensitive string function. This function is similar to the strncmp() function, with the difference that you can specify the number of characters from each...

1 minute read.

Python if-else

Python if-else The else statement is associated with if statement. An else statement executes if the conditional expression in if the statement becomes false or a Zero value. If the conditional expression...

2 minutes read.

PHP array_reverse() Function

PHP array_reverse() Function The array_reverse() function in PHP returns a new array with the elements in the reversed order. Syntax array_reverse (array $array [, bool $preserve_keys = FALSE ] ) Parameter array(required)- This parameter represents the input array preserve_keys (optional)- This parameter specifies if the function should preserve the keys...

1 minute read.

PHP array_shift() Function

PHP array_shift() Function The array_shift() in PHP shifts the first value of the array off. This function returns the same value after shortening the array by one element and moving everything. Syntax array_shift ( array &$array )  Parameter array(required)- This parameter represents the input array Return This function returns...

1 minute read.

PHP Switch Statement with Example

PHP switch statement The PHP switch statement is used to execute one condition from many conditions.It similar to if statements on the same expression. Syntax: switch(n) {             case1: statement if n=case1; break;             case2:             statement if n=case2; break;             case3:            ...

3 minutes read.

PHP Explode() Function

PHP Explode The PHP explode( ) is used to break a string into an array. The PHP explode( ) allow us to break a string into a smaller text with each break...

1 minute read.

PHP array_chunk() Function

PHP array_chunk() Function The array_chunk() function in PHP is used to split an array into chunks where the last chunk may contain less than size elements. Syntax array_chunk ( array $array , int $size [, bool $preserve_keys ]...

1 minute read.

PHP natcasesort() Function

PHP natcasesort() Function The natcasesort() function in PHP Sort an array using a case insensitive "natural order" algorithm while maintaining the keys. Syntax natcasesort ( array &$array ) Parameter array(required)- This parameter represents the input array. Return This parameter returns a Boolean...

1 minute read.

PHP Multidimensional Array

An array of arrays is called multidimensional array. It is used to store the data in a tabular form. It is represented in the form of matrix (row*column). Example: We can store...

2 minutes read.

PHP Operator

PHP Operator is used to perform operations on variable and values. Following are the types of Operator: PHP Arithmetic Operator PHP Arithmetic operator is used for arithmetical operations, such as addition, subtraction, multiplication...

2 minutes read.

PHP prev() Function

PHP prev() Function The prev() function in PHP rewinds or moves back the internal array pointer one place backward and returns the prev array value. It behaves like next() function, except that this function rewinds the...

1 minute read.

PHP vfprintf() Function

PHP vfprintf() Function The vfprintf() function in PHP writes a formatted string to a specified output stream. Syntax vfprintf ( resource $handle , string $format , array $args )  Parameter handle(required)- This parameter represents where to write the string. format(required)- This parameter specifies the string and how to format the...

3 minutes read.

PHP strcasecmp() Function

PHP strcasecmp() Function The strcasecmp() function in PHP compares two strings. It is a binary-safe case-insensitive string function. Syntax strcasecmp ( string $str1 , string $str2 ) Parameter str1(required)- This parameter represents the first string. str2(required)- This parameter represents the second string. Return This function returns a value less than( <...

1 minute read.

PHP nl_langinfo() Function

PHP nl_langinfo() Function The nl_langinfo() function in PHP returns specific local information. This function does not work on Windows platforms. Syntax nl_langinfo ( int $item ) Parameter Item(required)- This parameter specifies the  integer value of the element or the constant name of the...

1 minute read.

PHP array_combine() Function

PHP array_combine() Function The array_combine() function in PHP is used to create an array by combining two arrays i.e., one array for keys and another array for its values. Syntax array_combine ( array $keys , array $values ) Parameter keys(required)- This parameter represents an array which acts...

1 minute read.

PHP is_long() Function

The PHP is_long () function in PHP is used to find whether a variable is an integer or not. It returns a Boolean value true if the parameter var is integer else it returns...

1 minute read.

PHP array_keys() Function

PHP array_keys() Function The array_keys() function  in PHP is used to return all the keys, numeric and string from the given array. Syntax array_keys ( array $array ) or array_keys ( array $array , mixed $search_value [, bool $strict = FALSE ] )  Parameter array(required)- This parameter specifies the input array search_value(optional)- This parameter specifies a value, where...

1 minute read.

PHP quotemeta() Function

PHP quotemeta() Function The quotemeta() function in PHP quotes the meta characters and returns a string with a backslash character (\) before some predefine characters. The predefined characters are as follows: period ...

1 minute read.