Fatih Akgun
Fatih Akgun

Reputation: 553

echo html and php giving syntax error

There are similar questions on StackOverflow but I'm still having trouble fixing my problem. This is what I have

<video class="video-js vjs-default-skin" width="100%" poster="sqqsdqd.jpg" data-setup='{"controls":true, "autoplay": true, "preload": "auto"}'><source src="$media['data']['videos']['standard_resolution']['url']" type="video/mp4" /></video>

I need to echo it using php but whenever I try I'm getting a syntax error. This code:

echo '<div class="pic"><img src=" ' . $media['data']['images']['standard_resolution']['url'] . '"></div>';

is working fine but I can't figure out how to do it for the video one, help is appreciated. Thank you.

Edit: Sorry my actual code is like this

<?php 

if ($media['data']['type'] == 'image') {
  echo '<div class="pic"><img src=" ' . $media['data']['images']['standard_resolution']['url'] . '"></div>';
} else {
  echo '<video class="video-js vjs-default-skin" width="100%" poster="httjpg" data-setup='{"controls":true, "autoplay": true, "preload": "auto"}'> <source src=" '.$media['data']['videos']['standard_resolution']['url'].'" type="video/mp4" /></video>';
}

?>

Upvotes: 1

Views: 342

Answers (2)

Sathish
Sathish

Reputation: 2460

Just try this,

<?php
echo 'yourstuff';
?>
<video class="video-js vjs-default-skin" width="100%" poster="sqqsdqd.jpg" data-setup='{"controls":true, "autoplay": true, "preload": "auto"}'><source src="<?php echo $media['data']['videos']['standard_resolution']['url'] ?>" type="video/mp4" /></video>
<?php
echo 'yourstuff';
?>

update:

<?php 
if ($media['data']['type'] == 'image') {
  echo '<div class="pic"><img src=" ' . $media['data']['images']['standard_resolution']['url'] . '"></div>';
} else {
  ?>
<video class="video-js vjs-default-skin" width="100%" poster="sqqsdqd.jpg" data-setup='{"controls":true, "autoplay": true, "preload": "auto"}'><source src="<?php echo $media['data']['videos']['standard_resolution']['url'] ?>" type="video/mp4" /></video>
<?php
}
?>

I hope this will help to acheive

Upvotes: 1

ArtisticPhoenix
ArtisticPhoenix

Reputation: 21661

This issue comes because you have bad quoting style on this line

 '<video class="video-js vjs-default-skin" width="100%" poster="httjpg" data-setup='

See the apos ( single quotes ), there are several ways around this. The previous answer is one of them. Here is another

<?php 

if ($media['data']['type'] == 'image') {
    echo '<div class="pic"><img src=" ' . $media['data']['images']['standard_resolution']['url'] . '"></div>';
} else {
    echo <<<HTML
 <video class="video-js vjs-default-skin" width="100%" poster="httjpg" data-setup='{"controls":true, "autoplay": true, "preload": "auto"}'> <source src="{$media['data']['videos']['standard_resolution']['url']}" type="video/mp4" /></video>
HTML;
}
?>

Note that the closing HTML; must be on it's own line with no space before or after it. It's called a HEREDOC

Upvotes: 0

Related Questions