Easy Tutorial
❮ Php Floatval Function Func Filesystem Filetype ❯

PHP strcspn() Function

PHP String Reference Manual

Example

Outputs the number of characters searched before finding the character "w" in the string "Hello world!":


Definition and Usage

The strcspn() function returns the number of characters searched in the string before finding any of the specified characters (including spaces).

Tip: Use the strspn() function to find the number of characters in the string that contains only characters from a specified character list.

Note: This function is binary-safe.


Syntax

Parameter Description
string Required. Specifies the string to search.
char Required. Specifies the character to find.
start Optional. Specifies the position to start searching from.
length Optional. Specifies the length of the string (how many characters to search).

Technical Details

Return Value: Returns the number of characters searched in the string before finding any of the specified characters.
PHP Version: 4+
--- ---
Changelog: Added the start and length parameters in PHP 4.3.
--- ---

More Examples

Example 1

Using all parameters to output the number of characters searched before finding the character "w" in the string "Hello world!":


❮ Php Floatval Function Func Filesystem Filetype ❯