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

黄舟
Release: 2023-03-17 06:56:01
Original
1749 people have browsed it

Example

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

<?php
echo strspn("Hello world!","kHlleo");
?>
Copy after login

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)
Copy after login
ParametersDescription
string Required. Specifies the string to be searched for.
charlistRequired. Specifies the characters to search for.
startOptional. 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" 的数目:

<?php
echo strspn("abcdefand","abc");
?>
Copy after login

表头文件 #include  

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

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

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

范例

1 #include <string.h>  
2 #include <stdio.h>  
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   //开始不包含
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Return value: Returns the charlist parameter contained in the string The specified number of characters.
PHP Version: 4+
##Update Log :