0
我需要刪除部分以</div></div></div>
開頭的文本,以及在臨時目錄中的每個文件中的所有文本。 文本stucture基本相同:刪除每個文件中的部分文本
<!DOCTYPE html>
<head>
blah blah lots of text....
</div></div></div>
blah blah lots of text....
</div>
</html>
我做了什麼:
$files = scandir(__DIR__ . "/temp/");
$files = array_diff($files, array('.', '..'));
foreach($files as $file) {
$text_file = file_get_contents(__DIR__ . "/temp/".$file);
foreach($text_file as $txfile) {
$txfile = strstr($txfile, '</div></div></div>', true);
echo $txfile;
}
}
Warning: Invalid argument supplied for foreach()
,並試圖通過這種方式
$files = scandir(__DIR__ . "/temp/");
$files = array_diff($files, array('.', '..'));
foreach($files as $file) {
$text_file = file_get_contents(__DIR__ . "/temp/".$file);
for($i=0;$i<count($text_file);$i++)
{
$text_file = strstr($text_file[$i], '</div></div></div>', true);
echo $text_file;
}
}
甚至試圖與glob
但仍然沒有結果strstr
文件。