#navi(../)
* PHPで英文字の大文字小文字を区別せずに比較する関数・strcasecmp [#b5c6fe95]
PHPのstrcasecmp関数を使うと英字の大文字、小文字を区別せずに比較することができます。~
以下にサンプルスクリプト等を紹介します。

#contents
#htmlinsertpcsp(ll-top.html,ll-sp.html)

* strcasecmpのサンプルスクリプト [#p120b8b0]
strcasecmpの仕様は以下のリンクを確認してみてください。~
http://jp1.php.net/manual/ja/function.strcasecmp.php

#ref(strcasecmp.zip)
 <?php
 $a = "hello world";
 $b = "HELLO WORLD";
 
 if (strcmp($a, $b) != 0) {
   print("strcmp($a, $b) : not equal.\n");
 }
 if (strcasecmp($a, $b) == 0) {
   print("strcasecmp($a, $b) : equal.\n");
 }
 ?>
strcmpとstrcasecmpの比較のためにstrcmpとstrcasecmpの2つをサンプルスクリプトで使用しました。~
strcmp, strcasecmpともに内容が同一の場合は0が返却されます。

** strcasecmpサンプルスクリプトの実行結果 [#w748787a]
下記の出力の通り、英字の大文字小文字を区別せず比較できていることが確認できます。
 $ php strcasecmp.php
 strcmp(hello world, HELLO WORLD) : not equal.
 strcasecmp(hello world, HELLO WORLD) : equal.

以上、strcasecmpのPHPサンプルスクリプトでした。

#htmlinsertpcsp(ll-btm.html,ll-sp.html)

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS