【发布时间】: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有人吗? :)