简体   繁体   English

回显HTML和PHP给出语法错误

[英]echo html and php giving syntax error

There are similar questions on StackOverflow but I'm still having trouble fixing my problem. 在StackOverflow上也有类似的问题,但是我仍然无法解决问题。 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. 我需要使用php回显它,但是每当我尝试时都会遇到语法错误。 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>'; } ?> 

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 我希望这将有助于实现

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; 注意关闭HTML; must be on it's own line with no space before or after it. 必须在它自己的行之前或之后没有空格。 It's called a HEREDOC 叫做HEREDOC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM