【问题标题】:SubRip-File-Parser Unable to detect file encodingSubRip-File-Parser 无法检测文件编码
【发布时间】:2016-03-28 14:18:31
【问题描述】:

我正在尝试让这个 srt 到 vtt 转换器工作,但尝试时它一直说“无法检测文件编码”,这是我的代码。

require('src/SrtParser/srtFile.php');
if(isset($_POST['convert'])){
    try{
        $file = new \SrtParser\srtFile('./subtitle.srt');

        // display the text of the first entry
        echo $file->getSub(0)->getText();
        $file->mergeSrtFile($file2);
        $file->build();
        $file->save('./new_subtitles.vtt');

    }
    catch(Exception $e){
        echo 'Error: '.$e->getMessage()."\n";
    }
}

谁能告诉我我做错了什么,文件链接正确。

链接到 GitHub 上的文件解析器 delphiki/SubRip-File-Parser

【问题讨论】:

  • 呃,exec 启用了吗?可以用exec这个功能吗?解析器依赖它。
  • 正如 github 自述文件所说,该项目不再维护并移至github.com/captioning/captioning。或者,您可以尝试新项目。
  • 我一直不明白为什么人们会执行代码来尝试检测文本文件的字符编码。很明显,这根本不可能以任何可靠的方式实现。您有时可以证明某个文件可以以某种多字节编码进行编码,但无法以一般方式检测文件编码。 任何 文件都可以被认为以有效的 8 位编码保存文本。如果不猜测或使用一些显然不能精确的启发式方法,就不可能区分不同的 8 位编码。
  • 我确实尝试了github.com/captioning/captioning,但无法让它工作,它让我说Fatal error: Uncaught Error: Class 'Captioning\Format\SubripFile' not found in /Applications/XAMPP/xamppfiles/htdocs/websites/srt_to_vtt/index.php:5 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/websites/srt_to_vtt/index.php on line 5 有人吗? :)

标签: php file srt webvtt


【解决方案1】:

我建议在 Notepad++ 中打开文件并将编码转换为 UTF-8。

对于转换,您可以使用:

Subtitles::convert('subtitles.srt', 'new_subtitles.vtt');

https://github.com/mantas-done/subtitles

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    • 2010-10-05
    • 1970-01-01
    相关资源
    最近更新 更多