Change language

PHP Strspn () Function

Syntax:
strspn ($string, $charlist, $start, $length) 
Parameters:this the function takes four parameters as shown in the above syntax. The first two parameters are required and must be specified, while the other two parameters are optional. All of these parameters are described below:
  • $string:this required parameter specifies the string to search.
  • $charlist: this required parameter specifies a list of characters to find in the given string $.
  • $start:this optional parameter specifies the index at which we want to start searching in the string.
    • If $startis given and is not negative, then strspn() will start probing $stringfrom that position.
    • If $startand negative, then strspn() will start examining $string from that position at the end of $string.
  • $length: defines the number of characters $string to find. Its default value is - to the end of the line $.
    • If the value $lengthis set and it is not negative, then $string will be checked for the presence of $length characters from the starting position.
    • If $lengthis given and is negative, $string will be checked from the start position to $length characters from the end of $string.
Return value:This function returns the number of characters found in a string that contains only characters from the charlist parameter.Examples:
Input: $string = "abcdefghijk ", $charlist =" abcjkl "Output: 3 Input: $string =" Geeks for Geeks ", $charlist =" Geeksfor "Output: 15 
The following programs illustrate the strspn() function:Program 1:
// Output 15 because the entire input line
// contains all characters from the specified list of characters
// & quot; Hixfors & quot; echo strspn ( " Geeks for Geeks " , " Geeksfor " ); ?>
Output:
15 
Program 2:This program illustrates the case sensitivity of the strspn() function.
// Output is 0 because there is no substring
// which contains all the characters of this symbol
// list. echo strspn ( "Geeks for Geeks" , "engineer" ); ?>
Output:
0 
Program 3:This program illustrates the use of the strspn() function with the $start and $length parameters.
// Search for a substring starting at index 5
// and length 9 with all characters in the character
// list & quot; for & quot; echo strspn ( " Geeks for Geeks " , "for" , 5, 9); ?> Output:
5 
Program 4:This program illustrates the use of the strspn() function with a negative $length.
// Search from index 5 to 5th position from
// end. echo strspn ( "Geeks for Geeks" , "for" , 5, -5); ?>
Output:
5 
Program 5:This program illustrates the use of the strspn() function with a negative $start parameter.
// Search in the 5th index from the end echo strspn ( " Geeks for Geeks " , "for" , -5); ?> Output:
0 
Link:
http: / /php.net/manual/en/function.strspn.php

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically