PHP strspn() Function
In this chapter you will learn:
- Definition for PHP strspn() Function
- Syntax for PHP strspn() Function
- Parameter for PHP strspn() Function
- Return for PHP strspn() Function
- Example - Return the number of characters found in the string "abcdefand" that contains the characters "abc"
Definition
The strspn() function returns the number of characters found in the string that contains only characters from the charlist parameter.
Syntax
PHP strspn() Function has the following syntax.
strspn(string,charlist,start,length)
Parameter
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to search |
charlist | Required. | Characters to find |
start | Optional. | Where in the string to start |
length | Optional. | Length of the string |
Return
PHP strspn() Function returns the number of characters found in the string that contains only characters from the charlist parameter.
Example
Return the number of characters found in the string "Hello world!" that contains the characters "Java2s.com":
<?php
echo strspn("Hello world from java2s.com!","Java2s.com");
?>
Return the number of characters found in the string "abcdefand" that contains the characters "abc":
<?php
echo strspn("abcdefand","abc");
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP strstr() Function
- Syntax for PHP strstr() Function
- Parameter for PHP strstr() Function
- Return for PHP strstr() Function
- Example
- Example - tell if a sub string is found
- Example - returns the part of the haystack before the first occurrence of the needle (excluding the needle)
Home » PHP Tutorial » PHP String Functions