我试图做的是将25个文本文件的文件名和内容分别合并到一个单独的单词文件中,我已经实现了但条件是文件名应该是标题(在h1标签中)和内容每个文件都应该在下一行。如何实现这个目标?
<?php
for($i = 1; $i <= 25; $i++) {
$myfile = fopen('text/text_file'.$i.'.txt', 'w+') or die("Unable to open file!");
$txt = "This is the content of ".$i." file";
fwrite($myfile, $txt);
fclose($myfile);
}
$target = "text/";
$merged_file = 'text/merged.doc';
$files = scandir($target);
$myfile = fopen($merged_file, 'w+');
print_r($files);
foreach($files as $index => $value) {
if($value !== "." && $value !== ".." && substr($value, -3, 3) == "txt") {
$Data = substr($value, 0, -4)."\n".file_get_contents($target.$value);
$da= "<h2>".$Data."</h2>";
fwrite($myfile, $da."\n");
}
}
fclose($myfile);
?>