Home >
Backend Development >
PHP Tutorial >
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
黄舟
Release: 2023-03-17 06:56:01
Original
1781 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.
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!
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