2013-06-05 5 views
0

이 문제에 어려움이 있습니다. .mov 파일에서 데이터를 가져 와서 구문 분석 한 다음 원하는 데이터 만 출력하는 PHP 스크립트를 만들었습니다. 이제, 내 문제는 80 + 파일에 대해이 작업을 수행해야하며 동일한 디렉터리 (80 개 이상의 파일)에서 여러 파일을 읽은 다음 각 파일에서 생성 한 스크립트를 실행하여 어떻게 출력 할 수 있는지 궁금합니다. 데이터가 분리 되니? 코드를 완전히 변경해야합니까?디렉토리에서 여러 파일을 읽고 각 파일에서 스크립트를 실행하는 방법

다음
<?php 
$bg = "bg-body.png"; 
?> 

<html> 
<style type="text/css"> 
body { 
background-image: url('<?php echo $bg;?>'); 
background-repeat: repeat; 
background-position: top center; 
} 
</style> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Movie List</title> 
</html> 

<?php 

foreach (glob("*.mov") as $filename) 

$theData = file_get_contents($filename) or die("Unable to retrieve file data"); 

$months = ['January' => '_01', 'February' => '_02', 'March' => '_03', 'April' => '_04', 'May' => '_05', 'June' => '_06', 'July' => '_07', 'August' => '_08', 'September' => '_09', 'October' => '_10', 'November' => '_11', 'December' => '_12']; 
foreach($months as $key => $month){ 
    if(strpos($filename,$month)!==false){ 
     echo "<div style ='text-align: center; text-shadow: 0 .8px 0 #c4bc2a; margin-top: 30px; margin-bottom: 20px; font:16px verdana,tahoma,sans-serif; 
       color:#6b8942; font-weight:bold; text-decoration: underline;'>Movie List for $key 2013</div>"; 
    } 
} 


$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>"; 

?> 

그것이 출력 것입니다 : 여기

//[HMS Movie Line-Up File] 
//[Version 3] 
// Lineup=_2013_05 
// Field definitions for movie category lines: 
// 1. Category number (not used) 
// 2. Movie category name 
// 3. Regular price 
// 4. Discount price 
// 5. Type (Movies or Clips) 
// 6. Has synopsis (1 = Yes) 

// Field definitions for movie title lines: 
// 1. Menu Name 
// 2. Selection Number 
// 3. Adult or Non-adult (1 = adult) 
// 4. Asset Number 
// 5. Account Code 
// 6. Account Sub-Code 
// 7. Rating 
// 8. Running Time 
// 9. No. of Files 
// 10. File Name 
// 11. Movie Name 
// 12. Medium Type 
// 13. Tape Leader Time 
// 14. Begin Date 
// 15. Expire Date 
// 16. Preview Start-Time 1 
// 17. Preview Stop-Time 1 
// 18. Preview Start-Time 2 
// 19. Preview Stop-Time 2 
// 20. Preview Start-Time 3 
// 21. Preview Stop-Time 3 
// 22. Playback Control 
// 23. HDMI (1/0, 1 : use HDMI output) 
// 24. MoviePackage 
// 25. BitRate 
// 26. HD/SD content (H for HD content, S for non-HD, H3 is HD with AC3 audio) 
// 27. Aspect Ratio (16:9 or 4:3) 
// 28. Require HDCP (1/0, 1 is require) 
// 29. Movie trailer aduio type (0:MPEG audio, 1:AC3 audio) 

[Directory] 
1 Category 
1.1 hollywoodhd 
1.2 mega 
1.3 still 
1.4 special 
1.5 family 

[Categories] 
1 hollywoodhd 1295 1295 Movies 1 
2 mega 1095 1095 Movies 1 
3 still 1095 1095 Movies 1 
4 special 895 895 Movies 1 
5 family 1095 1095 Movies 1 

[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 
    hollywoodhd3 2 0 8007 0 928 PG-13 5735 1 guilttri_hd "(HD) The Guilt Trip" Disk 0 04/01/13 10/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0 
    hollywoodhd3 3 0 8013 0 928 PG-13 7813 1 jackreac_hd "(HD) Jack Reacher" Disk 0 04/01/13 10/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0 
    hollywoodhd4 1 0 7993 0 919 PG-13 9500 1 lesmiser_hd "(HD) Les Miserables" Disk 0 03/06/13 09/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0 
    hollywoodhd4 2 0 7997 0 919 PG-13 6031 1 mama_hd "(HD) Mama" Disk 0 03/15/13 09/25/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0 
    hollywoodhd4 3 0 8018 0 930 PG-13 6930 1 safehave_hd "(HD) Safe Haven" Disk 0 04/01/13 10/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0 
    hollywoodhd6 1 0 7971 0 926 PG 5063 1 placetab_hd "(HD) A Place at the Table" Disk 0 03/01/13 09/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0 
    hollywoodhd7 3 0 7952 0 928 PG 5470 1 cirqueso_hd "(HD) Cirque du Soleil: Worlds Away" Disk 0 02/01/13 08/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0 
    hollywoodhd8 1 0 7948 0 928 PG 5829 1 riseguar_hd "(HD) Rise of the Guardians" Disk 0 02/01/13 08/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0 
    hollywoodhd8 3 0 7950 0 928 PG-13 5181 1 funsize_hd "(HD) Fun Size" Disk 0 02/01/13 08/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0 
    hollywoodhd9 2 0 7947 0 930 PG-13 6054 1 shanghai_hd "(HD) Shanghai Calling" Disk 0 02/01/13 08/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0 
    hollywoodhd12 2 0 7868 0 930 NR 5722 1 package_hd "(HD) The Package" Disk 0 12/01/12 06/05/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0 
    hollywoodhd12 3 0 7851 0 931 PG-13 6045 1 housend_hd "(HD) The House at the End of the Street" Disk 0 11/01/12 06/05/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0 
    mega1 1 0 8060 0 702 PG-13 7413 1 beaucrea "Beautiful Creatures" Disk 0 05/01/13 10/15/13 0 0 0 0 0 0 1 0 0 3480400 S 16:9 0 0 
    mega1 2 0 8062 0 702 PG-13 6008 1 burtwond "The Incredible Burt Wonderstone" Disk 0 05/01/13 11/01/13 0 0 0 0 0 0 1 0 0 3480400 S 16:9 0 0 
    mega1 3 0 8063 0 702 PG-13 6850 1 jackgian "Jack the Giant Slayer" Disk 0 05/01/13 11/01/13 0 0 0 0 0 0 1 0 0 3480400 S 16:9 0 0 
    still1 2 0 7969 0 102 PG 6281 1 parental "Parental Guidance" Disk 0 02/15/13 08/01/13 0 0 0 0 0 0 1 0 0 3480400 S 4:3 0 0 
    still1 3 0 7977 0 702 PG-13 10162 1 hobbit1 "The Hobbit: An Unexpected Journey" Disk 0 03/01/13 09/01/13 0 0 0 0 0 0 1 0 0 3480400 S 16:9 0 0 
    still2 1 0 7902 0 702 PG-13 10303 1 cloudatl "Cloud Atlas" Disk 0 02/01/13 09/01/13 0 0 0 0 0 0 1 0 0 3480400 S 16:9 0 0 
    still2 2 0 7936 0 102 PG 7619 1 lifepi "Life of Pi" Disk 0 01/15/13 07/15/13 0 0 0 0 0 0 1 0 0 3480400 S 4:3 0 0 
    still3 2 0 7901 0 102 PG 6984 1 chasemav "Chasing Mavericks" Disk 0 01/01/13 07/01/13 0 0 0 0 0 0 1 0 0 3480400 S 16:9 0 0 
    still3 3 0 7872 0 102 PG-13 5529 1 taken2 "Taken 2" Disk 0 12/01/12 06/05/13 0 0 0 0 0 0 1 0 0 3480400 S 16:9 0 0 
    family1 1 0 7976 0 702 XXX 2418 1 arctic "Adult title 1" Disk 0 03/01/13 09/01/13 0 0 0 0 0 0 1 0 0 3480400 S 16:9 0 0 
    special1 1 0 5660 0 902 G 2743 1 fatdance "Fat Burning Hip Hop Dance Party" Disk 0 02/01/10 02/01/13 0 0 0 0 0 0 1 0 0 3500000 S 4:3 0 0 
    special1 2 0 5659 0 902 G 2731 1 fatgroov "Fat Burning Hip Hop Dance Grooves" Disk 0 02/01/10 02/01/13 0 0 0 0 0 0 1 0 0 3500000 S 4:3 0 0 
    special1 3 0 2266 0 903 G 4143 1 aladdin "Aladdin" Disk 0 02/01/04 12/31/20 0 0 0 0 0 0 0 0 0 3554800 S 4:3 0 0 
    special2 1 0 3236 0 913 NR 5028 1 americno "Americano" Disk 0 11/01/05 10/31/15 0 0 0 0 0 0 0 0 0 3500000 S 4:3 0 0 
    special2 2 0 3410 0 913 NR 6002 1 missbren "Missing Brendan" Disk 0 06/01/06 05/31/17 0 0 0 0 0 0 0 0 0 3500000 S 4:3 0 0 
    special2 3 0 2407 0 913 NR 5946 1 pointdoo "Point Doom" Disk 0 06/01/06 05/31/17 0 0 0 0 0 0 0 0 0 3500000 S 4:3 0 0 
    special3 1 0 2267 0 903 G 4528 1 gulliver "Gullivers Travels" Disk 0 02/01/04 12/31/20 0 0 0 0 0 0 0 0 0 3554800 S 4:3 0 0 
    special3 3 0 2279 0 907 PG 5575 1 princess "The Little Princess" Disk 0 03/01/04 03/31/20 0 0 0 0 0 0 0 0 0 3500000 S 4:3 0 0 
    special4 1 0 2278 0 907 PG 4915 1 jackbean "Jack And The Beanstalk" Disk 0 03/01/04 03/31/20 0 0 0 0 0 0 0 0 0 3500000 S 4:3 0 0 
    family1 1 0 7976 0 702 G 2418 1 arctic "To the Arctic" Disk 0 03/01/13 09/01/13 0 0 0 0 0 0 1 0 0 3480400 S 16:9 0 0 
    family1 1 0 7976 0 702 XXX 2418 1 arctic "Adult title 2" Disk 0 03/01/13 09/01/13 0 0 0 0 0 0 1 0 0 3480400 S 16:9 0 0 

내 PHP 스크립트이며, 여기에

가 .mov 파일 외모의 예 (다른 제목 각각 다릅니다.) 난 그냥 여러 파일에이 스크립트를 실행 한 후 각 파일 내 페이지의 출력을 생성 할 수 있다면

Movie List for July 2013 
Fat Burning Hip Hop Dance Party : G 
Fat Burning Hip Hop Dance Grooves : G 
Aladdin : G 
Gullivers Travels : G 
To the Arctic : G 
(HD) The Package : NR 
Americano : NR 
Missing Brendan : NR 
Point Doom : NR 
Parental Guidance : PG 
Life of Pi : PG 
Chasing Mavericks : PG 
(HD) Cirque du Soleil: Worlds Away : PG 
The Little Princess : PG 
(HD) Rise of the Guardians : PG 
(HD) A Place at the Table : PG 
(HD) Escape from Planet Earth : PG 
Jack And The Beanstalk : PG 
Taken 2 : PG-13 
Cloud Atlas : PG-13 
Jack the Giant Slayer : PG-13 
(HD) Mama : PG-13 
(HD) Safe Haven : PG-13 
(HD) Les Miserables : PG-13 
(HD) Jack Reacher : PG-13 
(HD) Dark Skies : PG-13 
(HD) The Guilt Trip : PG-13 
The Hobbit: An Unexpected Journey : PG-13 
(HD) Fun Size : PG-13 
The Incredible Burt Wonderstone : PG-13 
(HD) Identity Thief : PG-13 
(HD) Shanghai Calling : PG-13 
Beautiful Creatures : PG-13 
(HD) The House at the End of the Street : PG-13 
Adult title 2 : XXX 
Adult title 1 : XXX 

메시지가 완료됩니다.

답변

0

중 당신의 glob() 루프로 각 파일에 수집 모든 데이터를 할 수는

open file1 
get metadata1 
get metadata2 
get metadata3 
etc... 
open file2 
repeat... 

을 도달하거나 여러 루프를하고 메타 데이터의 각 유형을 얻고 보관 :

open file1 
get metadata1 
open file2 
get metadata2 
.... 

open file1 
get metadata2 
open file2 
get metadata2 
... 

첫 번째 옵션을 한 번만 각 파일을 방문하기 때문에 훨씬 더 효율적입니다.