Add variable to src file

Hi all

This is going to be really simple but I’m stumped

I’m adding a vimeo video to a page

I have the video ID which I’m using in an output variable that is then echoed.

In the output I break out of the variable and add the $video variable - ‘. $video .’


$video = 104226075

 $output = '<iframe src="https://player.vimeo.com/video/'. $video .'?title=0&amp;byline=0&amp;portrait=0" width="1000" height="528" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen class="embed-responsive-item"></iframe>';

 echo $output
 

I’m trying to do the same thing ut just using the html and adding the variable.


 <iframe src="https://player.vimeo.com/video/'<?php echo $video; ?>'?title=0&amp;byline=0&amp;portrait=0" width="1000" height="528" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen class="embed-responsive-item"></iframe>
 

I know this is just a syntax thing but I can’t get it to work.

How do I break out of the html and add the $video variable

Is it the single-quotes around the php angle-brackets in the second example? I see why you need them in the first, but not in the second. Failing that, when you view source what does the iframe code look like?

Hello

syntax is OK i think. There is some problem with PHP file maybe. Has it right extention?

Divide and conquer can help. As well as the heredoc notation.


<?php

error_reporting(E_ALL);

$video = 104226075;

$videoBase = 'https://player.vimeo.com/video/' . $video;

$videoQuery = http_build_query(array(
    'title'    => '0',
    'byline'   => '0',
    'portrait' => '0',
),'', '&amp;');

$videoUrl = $videoBase . '?' . $videoQuery;

echo $videoUrl . "\
\
";  // Just to check

$iframe = <<<EOT
<iframe src="$videoUrl"
  width="1000" height="528" frameborder="0"
  webkitallowfullscreen mozallowfullscreen allowfullscreen
  class="embed-responsive-item"
>
</iframe>
EOT;

echo $iframe . "\
";