<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.filesystem.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.fnmatch.php',
    1 => 'fnmatch',
    2 => 'ファイル名がパターンにマッチするか調べる',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'ファイルシステム 関数',
  ),
  'prev' => 
  array (
    0 => 'function.flock.php',
    1 => 'flock',
  ),
  'next' => 
  array (
    0 => 'function.fopen.php',
    1 => 'fopen',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/filesystem/functions/fnmatch.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.fnmatch" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">fnmatch</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">fnmatch</span> &mdash; <span class="dc-title">ファイル名がパターンにマッチするか調べる</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.fnmatch-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>fnmatch</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$pattern</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>fnmatch()</strong></span>は<code class="parameter">filename</code>
   で指定された文字列が
   <code class="parameter">pattern</code>
   で指定されたシェルワイルドカードにマッチするかどうかチェックします。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.fnmatch-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">pattern</code></dt>
     <dd>
      <p class="para">
       マッチさせるパターン。
       通常、<code class="parameter">pattern</code> には
       <code class="literal">&#039;?&#039;</code> や <code class="literal">&#039;*&#039;</code>
       のようなワイルドカードを含めます。
       <table class="doctable table">
        <caption><strong>
         <code class="parameter">pattern</code> で使えるワイルドカード
        </strong></caption>
        
         <thead>
          <tr>
           <th>ワイルドカード</th>
           <th>説明</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td>
            <code class="literal">?</code>
           </td>
           <td>
            クエスチョンマークは、1文字にマッチします。
            たとえば、
            <code class="literal">&quot;file?.txt&quot;</code> は <code class="literal">&quot;file1.txt&quot;</code>
            や <code class="literal">&quot;fileA.txt&quot;</code> にはマッチしますが、
            <code class="literal">&quot;file10.txt&quot;</code> にはマッチしません。
           </td>
          </tr>

          <tr>
           <td>
            <code class="literal">*</code>
           </td>
           <td>
            アスタリスクは、0文字以上の文字にマッチします。
            たとえば、
            <code class="literal">&quot;foo*.xml&quot;</code> は
            <code class="literal">&quot;foo.xml&quot;</code> や
            <code class="literal">&quot;foobar.xml&quot;</code> にマッチします。
           </td>
          </tr>

          <tr>
           <td>
            <code class="literal">[ ]</code>
           </td>
           <td>
            角括弧は、アスキー文字のコードポイントや、
            文字の集合を表すのに使います。
            たとえば、<code class="literal">&quot;index.php[45]&quot;</code>
            は <code class="literal">&quot;index.php4&quot;</code> や
            <code class="literal">&quot;index.php5&quot;</code> にマッチしますが、
            <code class="literal">&quot;index.phpt&quot;</code> にはマッチしません。
            よく知られている文字の範囲として
            <code class="literal">[0-9]</code>, <code class="literal">[a-z]</code>,
            <code class="literal">[A-Z]</code> が挙げられます。
            複数の集合や範囲は、同時に使うことができます。
            たとえば <code class="literal">[0-9a-zABC]</code> のように使えます。
           </td>
          </tr>

          <tr>
           <td>
            <code class="literal">!</code>
           </td>
           <td>
            エクスクラメーションマークは、
            角括弧内の文字を否定するのに使います。
            たとえば、<code class="literal">&quot;[!A-Z]*.html&quot;</code> は
            <code class="literal">&quot;demo.html&quot;</code> にマッチしますが、
            <code class="literal">&quot;Demo.html&quot;</code> にはマッチしません。
           </td>
          </tr>

          <tr>
           <td>
            <code class="literal">\</code>
           </td>
           <td>
            バックスラッシュは、特別な文字をエスケープするのに使います。
            たとえば、<code class="literal">&quot;Name\?&quot;</code> は
            <code class="literal">&quot;Name?&quot;</code> にマッチしますが、
            <code class="literal">&quot;Names&quot;</code> にはマッチしません。
           </td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>
    
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       調べたい文字列。この機能は特にファイル名のマッチに便利ですが、
       通常の文字列に関しても使用できます。
      </p>
      <p class="para">
       一般的なユーザーにとって、シェルパターンやあるいは少なくとも
       <code class="literal">&#039;?&#039;</code>と<code class="literal">&#039;*&#039;</code>によるワイルドカードのほうが
       慣れていると思われます。そのため、
       <span class="function"><a href="function.preg-match.php" class="function">preg_match()</a></span>
       の代わりに <span class="function"><strong>fnmatch()</strong></span>
       をフロントエンドの検索表現として使うことは、
       プログラマではないユーザーにとってより便利でしょう。
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">flags</code> の値は、以下のフラグを
       <a href="language.operators.bitwise.php" class="link">論理 OR (|) 演算子</a>
       で連結した任意の組み合わせです。
       <table class="doctable table">
        <caption><strong>
         <span class="function"><strong>fnmatch()</strong></span> で使えるフラグ
        </strong></caption>
        
         <thead>
          <tr>
           <th><code class="parameter">フラグ</code></th>
           <th>説明</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><strong><code><a href="filesystem.constants.php#constant.fnm-noescape">FNM_NOESCAPE</a></code></strong></td>
           <td>
            バックスラッシュのエスケープを無効にする。
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="filesystem.constants.php#constant.fnm-pathname">FNM_PATHNAME</a></code></strong></td>
           <td>
            文字列内のスラッシュは、指定したパターン内のスラッシュにのみマッチする。
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="filesystem.constants.php#constant.fnm-period">FNM_PERIOD</a></code></strong></td>
           <td>
            文字列の先頭のピリオドは、指定したパターン内のピリオドにマッチしなければならない。
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="filesystem.constants.php#constant.fnm-casefold">FNM_CASEFOLD</a></code></strong></td>
           <td>
            大文字小文字を区別しないマッチ。GNU 拡張の一部。
           </td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.fnmatch-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   マッチした場合に <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>、それ以外の場合に <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.fnmatch-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 シェルのワイルドカードパターンによる色の名前のチェック</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">fnmatch</span><span style="color: #007700">(</span><span style="color: #DD0000">"*gr[ae]y"</span><span style="color: #007700">, </span><span style="color: #0000BB">$color</span><span style="color: #007700">)) {<br />  echo </span><span style="color: #DD0000">"some form of gray ..."</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.fnmatch-notes">
  <h3 class="title">注意</h3>
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">
    今のところ、この機能は POSIX に準拠していないシステムで利用できません
    (ただし、Windows では利用できます)。
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.fnmatch-seealso">
  <h3 class="title">参考</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.glob.php" class="function" rel="rdfs-seeAlso">glob()</a> - パターンにマッチするパス名を探す</span></li>
    <li><span class="function"><a href="function.preg-match.php" class="function" rel="rdfs-seeAlso">preg_match()</a> - 正規表現によるマッチングを行う</span></li>
    <li><span class="function"><a href="function.sscanf.php" class="function" rel="rdfs-seeAlso">sscanf()</a> - フォーマット文字列に基づき入力を処理する</span></li>
    <li><span class="function"><a href="function.printf.php" class="function" rel="rdfs-seeAlso">printf()</a> - フォーマット済みの文字列を出力する</span></li>
    <li><span class="function"><a href="function.sprintf.php" class="function" rel="rdfs-seeAlso">sprintf()</a> - フォーマットされた文字列を返す</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>