特定の条件に一致するディレクトリ内のファイルを見つける必要があります。たとえば、ファイル名が「123-」で始まり、.txt で終わることは知っていますが、2 つの間に何があるかはわかりません。
ディレクトリ内のファイルと preg_match を取得するコードを開始しましたが、スタックしています。必要なファイルを見つけるためにこれを更新するにはどうすればよいですか?
$id = 123;
// create a handler for the directory
$handler = opendir(DOCUMENTS_DIRECTORY);
// open directory and walk through the filenames
while ($file = readdir($handler)) {
// if file isn't this directory or its parent, add it to the results
if ($file !== "." && $file !== "..") {
preg_match("/^".preg_quote($id, '/')."\\-(.+)\\.txt$/" , $file, $name);
// $name = the file I want
}
}
// tidy up: close the handler
closedir($handler);