0

拡張子「.mov」をスクリプトに取り込み、データを解析する PHP スクリプトを作成しました。しかし、問題は、多数の .mov ファイルを含むディレクトリがあり、スクリプトが最後のファイルのみをプルしていることです。

つまり、「Keating651.mov」「NickSHC809.mov」「Vill230.mov」などのディレクトリがあります...ディレクトリからプルして「NickSHC809」に一致するファイルをプルするようにコードを変更できますか? ...その後、スクリプトを実行しますか? そして、後で「Keating651」をプルするように変更すると、そのファイルだけがプルされますか?

foreach (glob('*.mov') as $filename){
    $theData = file_get_contents($filename) or die("Unable to retrieve file data");
}

$string = $theData;
$titles = explode("\n", $string);

function getInfo($string){
    $Ratings = ['G', 'PG', 'PG-13', 'R', 'NR', 'XXX'];
    $split = preg_split("/\"(.+)\"/", $string, 0, PREG_SPLIT_DELIM_CAPTURE); 
    if(count($split) == 3){ 
        preg_match("/(".implode("|", $Ratings).")\s/", $split[0], $matches);
        $rating = $matches[0];
        return ["title" => $split[1], "rating" => $rating];
    }
    return false;
}


$infolist = array();
foreach($titles as $title){
    $info = getInfo($title);
    if($info !== false){
    $infolist[] = $info;
    }
}

usort($infolist, "infosort");

function infosort($lhs,$rhs) {
  return strcmp($lhs['rating'], $rhs['rating']);
}

foreach ($infolist as $info) {
        echo "<div style ='margin-bottom: 3px; text-align: center;
          font:13px Verdana,tahoma,sans-serif;color:green;'> 
           {$info["title"]} : {$info["rating"]}</div>";
}

echo "<div style='text-align:center; margin-top: 20px;'><img src='shclogo.png'
alt='Logo' width='200' height='133'/></div>";

?>
4

1 に答える 1

0

質問を理解しているかどうかわかりません。その 1 つの特定のファイルのコンテンツが必要なだけで、取得するファイルを手動で変更しますか? 次に、これを変更できます

foreach (glob('*.mov') as $filename){
  $theData = file_get_contents($filename) or die("Unable to retrieve file data");
}

$theData = file_get_contents("NickSHC809.mov") or die("Unable to retrieve file data");

編集

あなたのコメントに従って、試してください

$matchedFiles = array();
foreach (glob('*.mov') as $filename){
  if (preg_match("/^(NickSHC809|Keating651)/i",$filename))
    $matchedFiles[] = $filename;
}
$useFile = reset($matchedFiles); // If you know there's just one file, otherwise do something to select the correct one
$theData = file_get_contents($useFile) or die("Unable to retrieve file data");
于 2013-06-07T16:52:59.723 に答える