title: PHP - Read few files
body: <pre><code>    $outputDir = $_SERVER['DOCUMENT_ROOT'] . "/dirName";
  
      $dir    = new RecursiveDirectoryIterator($outputDir);
      $rec    = new RecursiveIteratorIterator($dir);
      $a=3;
      $b = 10;
      $regex = '/Chapter[' .$a. ',' .$b. '/.html]$/';
      $it = new RegexIterator($rec, $regex);
  </code></pre>
  
  <p>I want to read all the files which is between $a and $b.</p>
  
  <p>If $a is 3 and $b is 5, then read <code>chapter3.html, chapter4.html, chapter5.html</code> </p>
  
  <p>But $it is null. I feel that I am missing something. Can you please help?</p>
  
  <p>var_dump on each statement returns</p>
  
  <p>$output dir looks like</p>
  
  <pre><code>    &lt;pre class='xdebug-var-dump' dir='ltr'&gt;&lt;small&gt;string&lt;/small&gt; &lt;font 
      color='#cc0000'&gt;'C:/server/httpd/Apache24/htdocs//front-page1//front-
       page//subjects//maths'&lt;/font&gt; &lt;i&gt;(length=73)&lt;/i&gt;
      &lt;/pre&gt;
  </code></pre>
  
  <p>Directory looks good</p>
  
  <p>Recursive directory iterator returns</p>
  
  <pre><code>     &lt;b&gt;object&lt;/b&gt;(&lt;i&gt;RecursiveDirectoryIterator&lt;/i&gt;)[&lt;i&gt;1&lt;/i&gt;]
       &lt;i&gt;private&lt;/i&gt; 'pathName' &lt;small&gt;(SplFileInfo)&lt;/small&gt; &lt;font  
         color='#888a85'&gt;=&amp;gt;&lt;/font&gt; &lt;small&gt;string&lt;/small&gt; &lt;font 
         color='#cc0000'&gt;'C:/server/httpd/Apache24/htdocs//front-page1//front-
         page//subjects//maths\.'&lt;/font&gt; &lt;i&gt;(length=75)&lt;/i&gt;
  
       &lt;i&gt;private&lt;/i&gt; 'fileName' &lt;small&gt;(SplFileInfo)&lt;/small&gt; &lt;font 
         color='#888a85'&gt;=&amp;gt;&lt;/font&gt; &lt;small&gt;string&lt;/small&gt; &lt;font 
         color='#cc0000'&gt;'.'&lt;/font&gt; &lt;i&gt;(length=1)&lt;/i&gt;
  
       &lt;i&gt;private&lt;/i&gt; 'glob' &lt;small&gt;(DirectoryIterator)&lt;/small&gt; &lt;font 
         color='#888a85'&gt;=&amp;gt;&lt;/font&gt; &lt;small&gt;boolean&lt;/small&gt; &lt;font    
         color='#75507b'&gt;false&lt;/font&gt;
  
      &lt;i&gt;private&lt;/i&gt; 'subPathName' &lt;font color='#888a85'&gt;=&amp;gt;&lt;/font&gt; 
      &lt;small&gt;string&lt;/small&gt; &lt;font color='#cc0000'&gt;''&lt;/font&gt; &lt;i&gt;(length=0)&lt;/i&gt;
      &lt;/pre&gt;
  </code></pre>
  
  <p>Directory looks invalid</p>
  
  <p>Recursive iterator iterator returns</p>
  
  <pre><code>    &lt;pre class='xdebug-var-dump' dir='ltr'&gt;
  
      &lt;b&gt;object&lt;/b&gt;(&lt;i&gt;RecursiveIteratorIterator&lt;/i&gt;)[&lt;i&gt;2&lt;/i&gt;]
  </code></pre>
  
  <p>What does this two mean?</p>
  
  <p>Regex is</p>
  
  <pre><code>   &lt;/pre&gt;&lt;pre class='xdebug-var-dump' dir='ltr'&gt;&lt;small&gt;string&lt;/small&gt; &lt;font 
       color='#cc0000'&gt;'/Chapter{0,5}\.html$/i'&lt;/font&gt; &lt;i&gt;(length=22)&lt;/i&gt;
     &lt;/pre&gt;
  </code></pre>
  
  <p>Regex iterator is</p>
  
  <pre><code>    &lt;pre class='xdebug-var-dump' dir='ltr'&gt;
  
         &lt;b&gt;object&lt;/b&gt;(&lt;i&gt;RegexIterator&lt;/i&gt;)[&lt;i&gt;3&lt;/i&gt;]
         &lt;i&gt;public&lt;/i&gt; 'replacement' &lt;font color='#888a85'&gt;=&amp;gt;&lt;/font&gt; &lt;font  
            color='#3465a4'&gt;null&lt;/font&gt;
      &lt;/pre&gt;
  </code></pre>