PHP strcspn()関数
例
「Helloworld!」で見つかった文字数を印刷します 文字「w」の前:
<?php
echo strcspn("Hello world!","w");
?>
定義と使用法
strcspn()関数は、指定された文字のいずれかの部分が見つかる前に、文字列で見つかった文字数(空白を含む)を返します。
ヒント:strspn()関数を使用して 、指定された文字リストの文字のみを含む文字列で見つかった文字数を指定します。
注:この関数はバイナリセーフです。
構文
strcspn(string,char,start,length)
パラメータ値
Parameter | Description |
---|---|
string | Required. Specifies the string to search |
char | Required. Specifies the characters to search for |
start | Optional. Specifies where in string to start |
length | Optional. Specifies the length of the string (how much of the string to search) |
技術的な詳細
戻り値: | 指定された文字のいずれかの部分が見つかる前に、文字列で見つかった文字数を返します |
---|---|
PHPバージョン: | 4歳以上 |
変更ログ: | 開始パラメーターと長さパラメーターはPHP4.3で追加されました |
その他の例
例
すべてのパラメーターを使用して、「Helloworld!」で見つかった文字数を出力します。文字「w」の前:
<?php
echo strcspn("Hello world!","w",0,6); // The start position is 0 and the length of the search string is 6.
?>
❮PHP文字列リファレンス