dongying6659 2015-10-08 10:21
浏览 14

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>
  • 写回答

2条回答 默认 最新

  • doufu8127 2015-10-08 10:31
    关注

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

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

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答