I would like to generate an "on-the-fly-generated" vtt file with PHP.
My code is as follows:
<?php
header('Content-Type: text/vtt; charset=utf-8');
header('Content-Disposition: inline; filename=data.vtt');
include 'connect.php';
if (isset($_GET["dbname"]))
{
$dbname = $_GET["dbname"];
}
if (isset($_GET["topnr"]))
{
$topnr = $_GET["topnr"];
}
$output = fopen('php://output', 'w');
$query = "SELECT * FROM `$dbname` WHERE `TOPNrReal` = $topnr LIMIT 0 , 1" ;
$queryOut = mysqli_query($con, $query);
while($row = mysqli_fetch_object($queryOut))
{
$vtt = $row->vtt;
}
fwrite($output, ltrim(utf8_encode($vtt)));
?>
This generates a dynamical vtt file.
The problem is now, that there are two leading whitespaces at the beginning of this file:
WEBVTT
00:00:00.000 --> 00:00:01.509
<i>Topic
16: First Topic</i>
I figured out, that tis issue occurs if the first header tag is set. But without this tag, there are other problems.
Is there any solution to eliminate this first two whitespaces?
Thanks in advance