Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 3226

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Find pathnames matching a pattern</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.fwrite.html">fwrite</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.is-dir.html">is_dir</a></div>
 <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><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)</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="type">array</span> <span class="methodname"><strong>glob</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   The  <span class="function"><strong>glob()</strong></span> function searches for all the pathnames
   matching <em><code class="parameter">pattern</code></em> according to the rules used by
   the libc glob() function, which is similar to the rules used by common
   shells.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.glob-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">pattern</code></em></span>
     <dd>

      <p class="para">
       The pattern. No tilde expansion or parameter substitution is done.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">flags</code></em></span>
     <dd>

      <p class="para">
       Valid flags:
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          <strong><code>GLOB_MARK</code></strong> - Adds a slash to each directory returned
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>GLOB_NOSORT</code></strong> - Return files as they appear in the
          directory (no sorting)
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>GLOB_NOCHECK</code></strong> - Return the search pattern if no
          files matching it were found
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>GLOB_NOESCAPE</code></strong> - Backslashes do not quote
          metacharacters
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>GLOB_BRACE</code></strong> - Expands {a,b,c} to match &#039;a&#039;, &#039;b&#039;,
          or &#039;c&#039;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>GLOB_ONLYDIR</code></strong> - Return only directory entries
          which match the pattern
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>GLOB_ERR</code></strong> - Stop on read errors (like unreadable
          directories), by default errors are ignored.
         </span>
        </li>
       </ul>
      </p>
     </dd>

    </dt>

   </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>FALSE</code></strong> on error.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    On some systems it is impossible to distinguish between empty match and an
    error.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.glob-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.1.0</td>
       <td>
        <strong><code>GLOB_ERR</code></strong> was added
       </td>
      </tr>

      <tr>
       <td>4.3.3</td>
       <td>
        <strong><code>GLOB_ONLYDIR</code></strong> became available on Windows and
        other systems not using the GNU C library
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.glob-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2398">
    <p><strong>Example #1 
     Convenient way how  <span class="function"><strong>glob()</strong></span> can replace
      <span class="function"><a href="function.opendir.html" 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&nbsp;(</span><span style="color: #0000BB">glob</span><span style="color: #007700">(</span><span style="color: #DD0000">"*.txt"</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$filename</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$filename</span><span style="color: #DD0000">&nbsp;size&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">filesize</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">)&nbsp;.&nbsp;</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="cdata"><pre>
funclist.txt size 44686
funcsummary.txt size 267625
quickref.txt size 137820
</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.html" 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>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    The <strong><code>GLOB_BRACE</code></strong> flag is not available on some non GNU
    systems, like Solaris.
   </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 class="member"> <span class="function"><a href="function.opendir.html" class="function" rel="rdfs-seeAlso">opendir()</a> - Open directory handle</span></li>
    <li class="member"> <span class="function"><a href="function.readdir.html" class="function" rel="rdfs-seeAlso">readdir()</a> - Read entry from directory handle</span></li>
    <li class="member"> <span class="function"><a href="function.closedir.html" class="function" rel="rdfs-seeAlso">closedir()</a> - Close directory handle</span></li>
    <li class="member"> <span class="function"><a href="function.fnmatch.html" class="function" rel="rdfs-seeAlso">fnmatch()</a> - Match filename against a pattern</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.fwrite.html">fwrite</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.is-dir.html">is_dir</a></div>
 <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>