【问题标题】:Overlaying text from YouTube API on image thumbnail在图像缩略图上覆盖来自 YouTube API 的文本
【发布时间】:2012-07-09 22:24:02
【问题描述】:

我已经设置了一个脚本,它使用数据 API 显示来自 YouTube 播放列表的最近视频缩略图。

我想从 $title 中获取前三个字符并将其覆盖在缩略图上,如何获取并显示此信息?我可以做 CSS,我只是不确定如何调用它。

目前的进度在...的视频连播中

当前的 PHP 代码是:

<?php
get_playlists();

function get_playlists(){
$data = file_get_contents("http://gdata.youtube.com/feeds/api/playlists/C82EBDAC0429B6A2?                  orderby=published&max-results=12");
$xml = simplexml_load_string($data);

foreach($xml->entry as $playlist){
$media = $playlist->children('http://search.yahoo.com/mrss/');
$attrs = $media->group->thumbnail[1]->attributes();
$thumb = $attrs['url'];
$attrs = $media->group->player->attributes();
$video = $attrs['url'];
$title = substr( $media->group->title, 27);
$url = $video;

parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
$vid_Id = $my_array_of_vars['v'];

$thumbnail .= '<div style="float:left; cursor:pointer;">
<p class="crop"><a class="videobox various iframe" href="http://www.youtube.com/embed/' .     $vid_Id . '?autoplay=1&hd=1"><img src="' .$thumb . '" title="' . $title . '" width="74"     height="56"/></a></p></div>';
}print $thumbnail;}
?>

【问题讨论】:

    标签: php api youtube


    【解决方案1】:
    $title = substr($media->group->title, 0, 3);
    

    您可以通过回显此变量来显示标题的前 3 个字符:

    echo $title;
    

    【讨论】:

    • 我想显示 original 标题的前 3 个字符,而不会干扰已经存在的其他 substr。因为我要抓取数字让它看起来像这样d.pr/i/G8oR(忽略工具提示上的数字,我没有数字)
    • 有人可以帮我解决这个问题吗?
    猜你喜欢
    • 2013-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 2021-06-13
    相关资源
    最近更新 更多