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