ディレクトリ(この場合はfiles/)を開き、このディレクトリ内のすべてのファイル名(ディレクトリまたは「..」または「.」を含まない)をスキャンし、検索するプログラムを作成しようとしています「ページ」配列からの指定されたファイルのファイル名。ファイル名がページに見つからない場合、ファイルは「unused-content」に移動されます。
現在のコードが機能しません。どうすればこの目標を達成できますか?
<?php
if($handle = opendir('files/')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$file_names[] = $entry;
}
}
closedir($handle);
}
$pages = array("page1.html","page2.shtml","page_three.shtml","page4.htm","page5.shtml");
for($x=0; $x<sizeOf($pages); $x++) {
$current_page = file_get_contents($pages[$x]);
for($i=0; $i<sizeOf($file_names); $i++) {
if(!strpos($current_page,$file_names[$i])) {
if (copy("files/".$file_names[$i],"files/unused-content/".$file_names[$i])) {
unlink("files/".$file_names[$i]);
}
}
}
}
?>
ありがとうございました!