返回列表 回复 发帖

我用PHP来合并中英字幕

我用PHP来合并中英字幕

英文字幕:

1
00:00:00,750 --> 00:00:02,350
previously on prison break:
2
00:00:02,380 --> 00:00:05,000
Give me the number for a sundown tel,please?

中文字幕:
1
00:00:00,750 --> 00:00:02,350
越狱前情提要
2
00:00:02,380 --> 00:00:05,000
请帮我查下Sundown旅馆的电话

合并后:
1
00:00:00,750 --> 00:00:02,350
越狱前情提要
previously on prison break:

2
00:00:02,380 --> 00:00:05,000
请帮我查下Sundown旅馆的电话
Give me the number for a sundown tel,please?

PHP代码:
  1. <?
  2. //////////////////////////
  3. //下面是英文剧本部分采集//
  4. //////////////////////////
  5. $cc=0; //数组开始量
  6. $filename = "./en.txt";
  7. $handle = file($filename);
  8. $enew = array();
  9. $total = array();
  10. $cc_total = 0;
  11. $cc_e_total = 4;
  12. $en_start =0;
  13. foreach ($handle as $key => $value)
  14. {
  15.    
  16.    if(ereg("^[1-9]",$value))
  17. {  
  18.    if ($value==($en_start+1))
  19.     {
  20.      $enew[$cc]=$key+2; //+2是为了把文字部分定位 因为数字和文字差两行。$gb_key+2为txt文本中文字所在的行数。
  21.      $cc++;
  22.      $en_start++;
  23.     }
  24.   }
  25. }
  26. reset($handle); //把英文剧本指针返回第一个。
  27. //下面是中文
  28. $gb_cc=0;
  29. $gb_start = 0;
  30. $gb_filename = "./gb.txt";
  31. $gb_handle = file($gb_filename);
  32. $gb_new = array();
  33. foreach ($gb_handle as $gb_key => $gb_value)  //$gb_handle是$gb_handle[0]=1 $gb_handle[1]=00:33:47,890 --> 00:33:48,610
  34. {
  35.    
  36.    if(ereg("^[1-9]",$gb_value))
  37. {  
  38.    
  39.     if ($gb_value==($gb_start+1))
  40.     {
  41.      $gb_new[$gb_cc]=$gb_key; //+2是为了把文字部分定位 因为数字和文字差两行。$gb_key+2为txt文本中文字所在的行数。
  42.      $gb_cc++;
  43.      $gb_start++;
  44.     }
  45.    
  46.    
  47.   }
  48. }
  49. reset($gb_handle); //把英文剧本指针返回第一个。

  50. foreach ($gb_new as $new_key => $new_value)  //中文在先$new_value开始于0
  51. {
  52.    $total[$cc_total]=$gb_handle[$new_value];
  53.    $total[$cc_total+1]=$gb_handle[$new_value+1];
  54.    $total[$cc_total+2]=$gb_handle[$new_value+2];
  55.    $total[$cc_total+3]=$gb_handle[$new_value+3];
  56.    //上面四个为中文 INDEX 和时间 和两行内容
  57.    $cc_total=$cc_total+7; //指针移动到$total[7]
  58. }
  59. foreach ($enew as $e_new_key => $e_new_value)
  60. {
  61.    $total[$cc_e_total]=$handle[$e_new_value];
  62.    $total[$cc_e_total+1]=$handle[$e_new_value+1];
  63.    $cc_e_total=$cc_e_total+7;
  64. }
  65. $total_count=count($total);
  66. for($e=0;$e<$total_count;$e++)
  67. {
  68.    
  69.    echo $total[$e]."<br />";

  70.   
  71. }

  72. ?>
复制代码
显示效果:
附件: 您所在的用户组无法下载或查看附件
^_^
提示: 作者被禁止或删除 内容自动屏蔽
24小时~挺好看的。
TC
ft  这是 prison break  ,越狱
九阴真经,请同学们多加练习
360行,行行出Bug。
哦,天哪,太牛了!!!
志当存高远!

在 php 的道路上实现真实的自我!

██████████████████████████████

msn/gtalk:hy0kle@gmail.com

寒沄
哈哈  欢迎使用.:lol  我去年11月写的 现在自己看不懂了呵呵.
好创意!
PEAR+Smarty模板架构的CMS

分享Smarty模板,送200MB空间
似乎是读取2个文件写成一个新文件!
返回列表