Latest web development tutorials

PHP strcspn () function

PHP String Reference PHP String Reference

Examples

"! Hello world" to find the output character "w" characters in the string before looking for:

<?php
echo strcspn("Hello world!","w");
?>

Running instance »

Definition and Usage

strcspn () function returns before finding any given character in the number of characters to find (including spaces).

Tip: the Use at The strspn () function to at The Number of characters found in at The String that the contains only characters from A specified Character List.

Note: This function is binary-safe.


grammar

strcspn( string,char,start,length )

参数 描述
string 必需。规定要搜索的字符串。
char 必需。规定要查找的字符。
start 可选。规定开始查找的位置。
length 可选。规定字符串的长度(搜索多少字符)。

technical details

return value: Back before finding any given character, the number of characters in the string to find.
PHP version: 4+
Update log: In PHP 4.3, add the start and length parameters.


More examples

Example 1

"! Hello world" to use all the parameters to find the character in the string output "w" characters before looking for:

<?php
echo strcspn("Hello world!","w",0,6); // The start position is 0 and the length of the search string is 6.
?>

Running instance »


PHP String Reference PHP String Reference