【问题标题】:Running two php scripts on subfolders using WAMP and Apache使用 WAMP 和 Apache 在子文件夹上运行两个 php 脚本
【发布时间】:2015-09-29 06:23:42
【问题描述】:

我正在尝试使用 php 做一些事情: 我有一个包含 2650 个子文件夹的文件夹……是的,那么多。 目前,我有 2 个脚本在每个子文件夹上处理一个 xml,但我必须手动进入每个文件夹,将 xml 复制到 www 文件夹,为每个文件夹运行两个脚本(localhost/script1.php 和 localhost/script2.php) ... 有没有办法在所有子文件夹上运行这两个脚本? 这是文件夹的结构:

C:\wamp\www\Games\Game1\Meta-inf\details.xml
C:\wamp\www\Games\Game2\Meta-inf\details.xml
C:\wamp\www\Games\Game3\Meta-inf\details.xml

我想运行一个脚本,我们称之为 runner.php,它执行以下操作:

http://localhost/runner.php
cd Games
cd Game-1
cd Meta-inf
RUN script1.php
RUN script2.php
cd ..
cd ..
cd Game-2
cd Meta-inf
RUN script1.php
RUN script2.php
.
.
.
cd Game-2650
cd Meta-inf
RUN script1.php
RUN script2.php

EXIT foreach
Exit php

这里的问题是我不知道如何制作一个进入 Gamex/Meta-inf/ 并处理 xml 的新 php 脚本。 2 个脚本中的每一个都会创建一个新文件(1 个 excel 和 1 个 txt),这些文件应该在 /Game/Gamex/ 文件夹中创建...应该在每个脚本上进行修改吧?

非常感谢!

【问题讨论】:

  • 你见过glob吗?您可以将/Game-*/Meta-inf 的模式传递给它,并获取您可以循环的所有目录的数组。

标签: php xml apache subdirectory run-script


【解决方案1】:

多亏了 petebolduc 和 Tom Hart,我才得以弄清楚。 我将在这里留下完整的代码(我使用 echo 进行测试...)

非常感谢!!!!!!

<?php
foreach(glob("C:\\Users\\Usuario\\Desktop\\Nuevos_Juegos\\SM\\*\\META-INF\\") as $folder)
{
    $xml = simplexml_load_file("$folder\\details.xml");
     $result = $xml->xpath('//name');
     foreach ($result as $node) 
     {
        if ( ($node['lang'] == 'en')  )
        {
            echo "$node" . "<br>";
        }

     } 
}
?>

【讨论】:

    【解决方案2】:

    glob() 将读取每个文件夹:

    foreach(glob('FULL-PATH-TO/Gamex/Meta-inf/*') as $folder) {
    
      // process each folder in here...
    
    }
    

    如果您将处理文件中的现有代码包装在 glob() 函数中,它将满足您的需求。

    【讨论】:

      猜你喜欢
      • 2019-07-28
      • 2013-03-05
      • 2015-10-17
      • 1970-01-01
      • 2019-05-14
      • 2014-06-11
      • 2020-05-08
      • 1970-01-01
      • 2018-11-19
      相关资源
      最近更新 更多