1

I've got a text file that contains a youtube url code for example: BzRBCM89GvI

I want this to be placed inside a iFrame and the title of the file to be used as a title above the video. I almost have it but for some reason the link does not appear to be working. If i inspect the element the URL LOOKS good but when i copy paste it to a text editor i get this: https://www.youtube.com/embed/%EF%BB%BFBzRBCM89GvI

The extra: "%EF%BB%BF" mess it up i think.

This is the PHP code:

<?PHP
$projects = glob('images/Projects/Video/*');

foreach ($projects as &$project) {  
    $src = "https://www.youtube.com/embed/" . file_get_contents($project);
    echo'<h3>' . str_replace(".txt","",str_replace("images/Projects/Video/","",$project)) . '</h3><iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" style="min-height: 300px; width: 100%;" type="text/html" src="' . $src . '"></iframe>';
}
?>

Any idea's why the extra bits are added or why it's not working?

DjKillerMemeStar
  • 425
  • 5
  • 18

1 Answers1

1

That's the Byte Order Mark (BOM) of a UTF-8 encoded file. Save the file without BOM. Most text editors have this ability.

If you don't have control of the file and need to remove the BOM, check How to remove multiple UTF-8 BOM sequences

Skipping the first 3 characters/bytes might also work, but this assumes that the BOM is always present:

substr(file_get_contents($project), 3);
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87