I've spent a big portion of today solving this. But couldn't.
Basically, I want to embed an Youtube video in a PHP page. The videoid
variable is defined in the PHP page but I cannot make the JS display that variable.
<script>
// Load the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
height: '460',
width: '760',
videoId: '<? echo $var;>'
});
}
</script>
The $var
variable is present globally within the PHP file but it doesn't work. I also declared a variable within the JS, with no success. What am I doing wrong?
Edit:
Since it's marked as duplicate, let me explain. I'm not having an issue understanding how to output the PHP variable, it just doesn't work, no matter how I try.