PHP strcspn()関数

PHP String 参考手册PHP String リファレンスマニュアル

例

文字列 "Hello world!" の中で文字 "w" が見つかる前に検索した文字数を出力します:

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

例を実行 »

定義と使用法

strcspn() 関数は、指定された文字が見つかる前に文字列内で検索した文字数(スペースを含む)を返します。

ヒント: 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)

パラメータ 説明
string 必須。検索する文字列を指定します。
char 必須。検索する文字を指定します。
start 省略可能。検索を開始する位置を指定します。
length 省略可能。文字列の長さ(検索する文字数)を指定します。

技術詳細

戻り値: 指定された文字が見つかる前に文字列内で検索した文字数を返します。
PHP バージョン: 4+
更新ログ: PHP 4.3 で、新しいstartとlengthパラメータが追加されました。


その他の例

例 1

すべてのパラメータを使用して、文字列 "Hello world!" の中で文字 "w" が見つかる前に検索した文字数を出力します:

<?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 リファレンスマニュアル その他の拡張