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

Nov 06, 2017 am 09:23 AM
php string

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

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