PHP - 阅读几个文件

    $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);

I want to read all the files which is between $a and $b.

If $a is 3 and $b is 5, then read chapter3.html, chapter4.html, chapter5.html

But $it is null. I feel that I am missing something. Can you please help?

var_dump on each statement returns

$output dir looks like

    <pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font 
    color='#cc0000'>'C:/server/httpd/Apache24/htdocs//front-page1//front-
     page//subjects//maths'</font> <i>(length=73)</i>
    </pre>

Directory looks good

Recursive directory iterator returns

     <b>object</b>(<i>RecursiveDirectoryIterator</i>)[<i>1</i>]
     <i>private</i> 'pathName' <small>(SplFileInfo)</small> <font  
       color='#888a85'>=&gt;</font> <small>string</small> <font 
       color='#cc0000'>'C:/server/httpd/Apache24/htdocs//front-page1//front-
       page//subjects//maths\.'</font> <i>(length=75)</i>

     <i>private</i> 'fileName' <small>(SplFileInfo)</small> <font 
       color='#888a85'>=&gt;</font> <small>string</small> <font 
       color='#cc0000'>'.'</font> <i>(length=1)</i>

     <i>private</i> 'glob' <small>(DirectoryIterator)</small> <font 
       color='#888a85'>=&gt;</font> <small>boolean</small> <font    
       color='#75507b'>false</font>

    <i>private</i> 'subPathName' <font color='#888a85'>=&gt;</font> 
    <small>string</small> <font color='#cc0000'>''</font> <i>(length=0)</i>
    </pre>

Directory looks invalid

Recursive iterator iterator returns

    <pre class='xdebug-var-dump' dir='ltr'>

    <b>object</b>(<i>RecursiveIteratorIterator</i>)[<i>2</i>]

What does this two mean?

Regex is

   </pre><pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font 
     color='#cc0000'>'/Chapter{0,5}\.html$/i'</font> <i>(length=22)</i>
   </pre>

Regex iterator is

    <pre class='xdebug-var-dump' dir='ltr'>

       <b>object</b>(<i>RegexIterator</i>)[<i>3</i>]
       <i>public</i> 'replacement' <font color='#888a85'>=&gt;</font> <font  
          color='#3465a4'>null</font>
    </pre>

Regex doesn't look correct to me. I think it should be:

$regex = '/Chapter{' .$a. ',' .$b. '}\.html$/';

Like this you can get the path(s) to the desired files:

 $a=3;
 $b=5;

var_dump(glob(dirname(__FILE__).'/test/chapter*['.$a.'-'.$b.'].html')) ;

dirname(__FILE__) is to go from the place where this file is. So my test scenario looked like this

|____index.php
|____test
| |____chapter1.html
| |____chapter2.html
| |____chapter3.html
| |____chapter4.html
| |____chapter5.html
| |____chapter6.html