I have a directory that contains a lot of folders only and each of those folder has a text file that contain urls what Im trying to do is to create a php code that will open that text file on each that folder and will edit that and make that urls in a single line with \n character separating each urls
This is my code so far
$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);