Home  >  Article  >  Backend Development  >  php function strspn() that returns a string containing the number of characters specified in the charlist parameter

php function strspn() that returns a string containing the number of characters specified in the charlist parameter

黄舟
黄舟Original
2017-11-06 09:23:151636browse

Example

Returns the number of characters "kHlleo" contained in String "Hello world!":

Definition and usage

The strspn() function returns the number of characters in a string containing the number of characters specified in the charlist parameter.

Tip: Please use the strcspn() function to return the number of characters searched in a string before any specified character is found.

Note: This function is binary safe.

Syntax

strspn(string,charlist,start,length)
Parameters Description
string Required. Specifies the string to be searched for.
charlist Required. Specifies the characters to search for.
start Optional. Specifies where in the string to begin.
length Optional. Defines the length of the string.

Technical details

In PHP 4.3, new start and length parameters were added.

更多实例

实例 1

返回在字符串 "abcdefand" 中包含字符 "abc" 的数目:

表头文件 #includebbed3fed50f96ac7490cfc6a498c4bc5  

定义函数 size_t strspn (const char *s,const char * accept);  

函数说明 strspn()从参数s 字符串的开头计算连续的字符,而这些字符都完全是accept所指字符串中的字符。简单的说,若strspn()返回的数值为n,则代表字符串s 开头连续有n个字符都是属于字符串accept内的字符。  

返回值 返回字符串s开头连续包含字符串accept内的字符数目。

范例

1 #include   
2 #include   
3 main()  
4 {  
5 char *str="Linux was first developed for 386/486-based pcs.";  
6 printf("%d\n",strspn(str,"Linux"));  
7 printf("%d\n",strspn(str,"/-"));  
8 printf("%d\n",strspn(str,"1234567890"));  
9 }  运行结果:  
5  //包含linux字符切  
0  // 开始不包含  
0   //开始不包含


Return value: Returns the charlist parameter contained in the string The specified number of characters.
PHP Version: 4+
##Update Log :

The above is the detailed content of php function strspn() that returns a string containing the number of characters specified in the charlist parameter. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn