<?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 => 'ru',
  ),
  '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' => 'ru',
    '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="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>
            Вопросительный знак соответствует одному произвольному символу.
            Шаблон <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>
            Звёздочка соответствует нулю или большему количеству символов.
            Шаблон <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>
            Квадратные скобки задают диапазоны или наборы отдельных символов в границах кодовых точек стандарта ASCII.
            Шаблон <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"><strong>fnmatch()</strong></span>, а не <span class="function"><a href="function.preg-match.php" class="function">preg_match()</a></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">оператором | — побитового ИЛИ</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 /><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">"Какая-то форма серого цвета..."</span><span style="color: #007700">;<br />}</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); ?>