我创建了一个 PHP 脚本,它将扩展名“.mov”拉入脚本,然后解析数据。但问题是,我有一个包含一堆 .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>";
?>