doubiao9775 2014-03-08 14:51
浏览 44
已采纳

如何使用echo在数据图像中添加php代码

I'm using my data to get an iframe src, because I'm using this data in my function.js.

for example, with this youtube video :

my custom field with the youtube id :

<?php the_sub_field('youtube'); ?>

my thumbnail is :

<img src="http://img.youtube.com/vi/<?php the_sub_field('youtube'); ?>/0.jpg" class="photo_medias"/>

and my Iframe :

<iframe width="706" height="364"  src="//www.youtube.com/embed/<?php the_sub_field('youtube'); ?>?showinfo=0&controls=0" frameborder="0" allowfullscreen>

and when adding this to a img data :

<img src="http://img.youtube.com/vi/<?php the_sub_field('youtube'); ?>/0.jpg"  data-videofull='<iframe width="706" height="364"  src="//www.youtube.com/embed/<?php the_sub_field('youtube'); ?>?showinfo=0&controls=0" frameborder="0" allowfullscreen>"' class="photo_medias">

it works perfectly.

Now I'm trying to generate another data-videofull but with a vimeo code, which is a bit different to generate the thumbnail and to display it

here is my custom field with vimeo id :

<?php the_sub_field('vimeo'); ?>

my thumbnail is (this is where it's a bit different, I need to use echo inside)

<?php echo '<img src="' . get_vimeo_thumb(get_sub_field('vimeo'), 'thumbnail_large') . '"" class="photo_medias" >';?>

my iframe (same as for youtube)

<iframe width="706" height="364"  src="//player.vimeo.com/video/<?php the_sub_field('vimeo'); ?>?title=0" frameborder="0" allowfullscreen></iframe>

but when trying to add the iframe adress into data-videofull, I have a php error...

this is what I tried, but it's not working :

<?php echo '<img src="' . get_vimeo_thumb(get_sub_field('vimeo'), 'thumbnail_large') . '"" data-videofull='<iframe width="706" height="364"  src="//player.vimeo.com/video/<?php the_sub_field('vimeo'); ?>?title=0" frameborder="0" allowfullscreen></iframe>' class="photo_medias" >';?>

I guess the problem comes from the echo of my img src but I have to use it...

can anybody help me with this ?

thanks a lot for your help,

  • 写回答

2条回答 默认 最新

  • dtny30176 2014-03-08 14:56
    关注

    There is something wrong, you need to escape single quotes and also don't put php tags inside php other tags but concatenate your strings and functions. Also you have a double double quotes which i removed.

    <?php echo '<img src="' . get_vimeo_thumb(get_sub_field('vimeo'), 'thumbnail_large') . '" data-videofull=\'<iframe width="706" height="364"  src="//player.vimeo.com/video/'.the_sub_field('vimeo').'?title=0" frameborder="0" allowfullscreen></iframe>\' class="photo_medias" >';?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决