PHP strncmp()関数
例
2つの文字列を比較します(大文字と小文字を区別):
<?php
echo strncmp("Hello world!","Hello earth!",6);
?>
定義と使用法
strncmp()関数は2つの文字列を比較します。
注: strncmp()はバイナリセーフであり、大文字と小文字が区別されます。
ヒント:この関数は strcmp()関数に似ていますが、strcmp()に長さパラメーターがない点が異なります。
構文
strncmp(string1,string2,length)
パラメータ値
Parameter | Description |
---|---|
string1 | Required. Specifies the first string to compare |
string2 | Required. Specifies the second string to compare |
length | Required. Specify the number of characters from each string to be used in the comparison |
技術的な詳細
戻り値: | この関数は次を返します。
|
---|---|
PHPバージョン: | 4歳以上 |
その他の例
例
2つの文字列を比較します(大文字と小文字を区別= HelloとhELLoは同じものを出力しません):
<?php
echo strncmp("Hello","Hello",6);
echo "<br>";
echo strncmp("Hello","hELLo",6);
?>
❮PHP文字列リファレンス