我创建了一个 php 文件,我试图用它来解析数据。我要解析的文件内容如下所示:
[Titles]
hollywoodhd1 1 0 8046 0 919 PG-13 6712 1 identity_hd "(HD) Identity Thief" Disk 0 04/15/13 11/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0
hollywoodhd2 3 0 8016 0 930 PG 5347 1 escapep_hd "(HD) Escape from Planet Earth" Disk 0 04/01/13 10/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0
hollywoodhd3 1 0 8012 0 930 PG-13 5828 1 darkski_hd "(HD) Dark Skies" Disk 0 04/01/13 10/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0
我创建的 PHP:
<?php
foreach (glob("*.mov") as $filename)
$theData = file_get_contents($filename) or die("Unable to retrieve file data");
// echo nl2br($theData); //- This will print the entire text-wrapped line breaks.
$Ratings = ['G', 'PG', 'PG-13', 'R', 'NR', 'XXX']; // - This doesn't do anything yet.
if (preg_match('!"([^"]+)"!', $theData, $m)){
echo $m[1];
}
?>
问题:我想返回 MOVIE TITLE : RATING,但到目前为止我的代码只返回一个电影标题,(HD) Identity Thief。我还有很长的路要走,所以任何指导将不胜感激。有没有办法严格按照收视率对电影标题进行排序:收视率?
此外,有没有办法让 PHP 脚本搜索目录和任何“.mov”文件扩展名的子文件夹,为每个文件运行脚本?