我有一个只包含很多文件夹的目录,每个文件夹都有一个包含 url 的文本文件,我想做的是创建一个 php 代码,该代码将在每个文件夹上打开该文本文件并对其进行编辑并制作该 url 在一行中,用 \n 字符分隔每个 url
到目前为止,这是我的代码
$path = "localpath here";
$handle = opendir($path);
while ($file = readdir($handle)) {
    if(substr($file,0,1) !="."){
        $text = preg_replace('/\s+/', '', $file);
        //echo $text."</br>";
        $blast = fopen("$path/$text/$text.txt", 'r') or die("can't open file");
        //echo $blast;
        while (!feof($blast)) {
            $members[] = fgets($blast);
            //echo $members;
        }
    }
}
foreach($members as $x=> $order){
    echo $order."</br>";
    $string = trim(preg_replace('/\s+/', ' ', $order));
    $linksonly = "write.txt";
    $linksonlyHandle = fopen("$path/$text/$linksonly", 'a') or die("can't open file");
    fwrite($linksonlyHandle,$string.'\n');
    fclose($linksonlyHandle);
}
closedir($handle);