<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.glob.php',
    1 => 'glob',
    2 => 'Find pathnames matching a pattern',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Filesystem Functions',
  ),
  'prev' => 
  array (
    0 => 'function.fwrite.php',
    1 => 'fwrite',
  ),
  'next' => 
  array (
    0 => 'function.is-dir.php',
    1 => 'is_dir',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/filesystem/functions/glob.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.glob" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">glob</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">glob</span> &mdash; <span class="dc-title">Find pathnames matching a pattern</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.glob-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>glob</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.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   The <span class="function"><strong>glob()</strong></span> function searches for all the pathnames
   matching <code class="parameter">pattern</code> according to the rules used by
   the libc glob() function, which is similar to the rules used by common
   shells.
  </p>
  <p class="simpara">
   The behavior on Unix systems and macOS is determined by the system&#039;s
   implementation of glob(). On Windows, an implementation that conforms
   to the POSIX 1003.2 definition for glob() is used, and it includes
   an extension to handle the <code class="literal">[!...]</code> convention for
   negating a range.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.glob-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">pattern</code></dt>
     <dd>
      <p class="para">
       The pattern. No tilde expansion or parameter substitution is done.
      </p>
      <p class="para">
       Special characters:
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          <code class="literal">*</code> - Matches zero or more characters.
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <code class="literal">?</code> - Matches exactly one character (any character).
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <code class="literal">[...]</code> - Matches one character from a group of
          characters. If the first character is <code class="literal">!</code>,
          matches any character not in the group.
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <code class="literal">{a,b,c}</code> - Matches one string from a group of
          strings delimited by a comma when the <strong><code><a href="filesystem.constants.php#constant.glob-brace">GLOB_BRACE</a></code></strong>
          flag is used.
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <code class="literal">\</code> - Escapes the following character,
          except when the <strong><code><a href="filesystem.constants.php#constant.glob-noescape">GLOB_NOESCAPE</a></code></strong> flag is used.
         </span>
        </li>
       </ul>
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       Any of the <strong><code><a href="filesystem.constants.php#constant.glob-available-flags">GLOB_<span class="replaceable">*</span></a></code></strong> constants.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.glob-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an array containing the matched files/directories, an empty array
   if no file matched or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on error.
   Unless <code class="literal">GLOB_NOSORT</code> was used, the names will
   be sorted alphanumerically.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.glob-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 
     Convenient way how <span class="function"><strong>glob()</strong></span> can replace
     <span class="function"><a href="function.opendir.php" class="function">opendir()</a></span> and friends.
    </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">foreach (</span><span style="color: #0000BB">glob</span><span style="color: #007700">(</span><span style="color: #DD0000">"*.txt"</span><span style="color: #007700">) as </span><span style="color: #0000BB">$filename</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$filename</span><span style="color: #DD0000"> size " </span><span style="color: #007700">. </span><span style="color: #0000BB">filesize</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">funclist.txt size 44686
funcsummary.txt size 267625
quickref.txt size 137820</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>Example #2 
     Example with a more complex pattern
    </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">foreach (</span><span style="color: #0000BB">glob</span><span style="color: #007700">(</span><span style="color: #DD0000">"path/*/*.{txt,md}"</span><span style="color: #007700">, </span><span style="color: #0000BB">\GLOB_BRACE</span><span style="color: #007700">) as </span><span style="color: #0000BB">$filename</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$filename</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">path/docs/mailinglist-rules.md
path/docs/README.md
path/docs/release-process.md
path/pear/install-pear.txt
path/Zend/README.md</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.glob-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">This function will not work on
<a href="features.remote-files.php" class="link">remote files</a> as the file to
be examined must be accessible via the server&#039;s filesystem.</span></p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    This function isn&#039;t available on some systems (e.g. old Sun OS).
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.glob-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.opendir.php" class="function" rel="rdfs-seeAlso">opendir()</a> - Open directory handle</span></li>
    <li><span class="function"><a href="function.readdir.php" class="function" rel="rdfs-seeAlso">readdir()</a> - Read entry from directory handle</span></li>
    <li><span class="function"><a href="function.closedir.php" class="function" rel="rdfs-seeAlso">closedir()</a> - Close directory handle</span></li>
    <li><span class="function"><a href="function.fnmatch.php" class="function" rel="rdfs-seeAlso">fnmatch()</a> - Match filename against a pattern</span></li>
   </ul>
  </p>
 </div>


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