PHP strcspn() 函數(shù)

2018-11-21 14:50 更新

PHP strcspn() 函數(shù)

PHP String 參考手冊 PHP String 參考手冊

實例

輸出在字符串 "Hello world!" 中找到字符 "w" 之前查找的字符數(shù):

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

運行實例 ?

定義和用法

strcspn() 函數(shù)返回在找到任何指定的字符之前,在字符串查找的字符數(shù)(包括空格)。

提示: Use the strspn() function to the number of characters found in the string that contains only characters from a specified character list.

注釋: This function is binary-safe.


語法

strcspn(string,char,start,length)

參數(shù) 描述
string 必需。規(guī)定要搜索的字符串。
char 必需。規(guī)定要查找的字符。
start 可選。規(guī)定開始查找的位置。
length 可選。規(guī)定字符串的長度(搜索多少字符)。

技術(shù)細節(jié)

返回值: 返回在找到任何指定的字符之前,在字符串查找的字符數(shù)。
PHP 版本: 4+
更新日志: 在 PHP 4.3 中,新增了 startlength 參數(shù)。


更多實例

實例 1

使用所有的參數(shù)來輸出在字符串 "Hello world!" 中找到字符 "w" 之前查找的字符數(shù):

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

運行實例 ?


PHP String 參考手冊 PHP String 參考手冊
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號