【问题标题】:Formatting embedded YouTube video descriptions格式化嵌入的 YouTube 视频说明
【发布时间】:2013-05-12 04:34:12
【问题描述】:

我有一个 PHP 函数,可以从 API 获取我最新的 YouTube 视频,我可以访问描述,但它没有格式化,即它基本上是一行文本,有没有办法让 \n 实际打印一个换行?

这是函数

    function get_latestvideo($username)
{
    $videos = array();

    $data = "http://gdata.youtube.com/feeds/api/users/{$username}/uploads?start-index=1&max-results=4&v=2&alt=json";
    foreach (json_decode(file_get_contents("$data"))->feed->entry as $video)
    {
        $videos[] = array(
            'title' => $video->title->{'$t'},
            'desc' => $video->{'media$group'}->{'media$description'}->{'$t'},
            'url' => $video->content->src,
            'thumbnail' => $video->{'media$group'}->{'media$thumbnail'}[1]->url,
        );
    }
return $videos;
}

这是直接来自 API 的描述

   "media$description": {
    "$t": "Enjoy, Like, Comment, Subscribe\nGiggleSquid's Twitter: https://twitter.com/GiggleSquid\nGigglesquid's Facebook: http://www.facebook.com/GiggleSquid\n\nGiggleSquid and dapaka delve into SimCity in a hopeless attempt to develop an efficient, bustling metropolis, will they succeed? No, probably not\n\nOutro Music:\nOne-eyed Maestro by the amazing Kevin MacLeod (incompetech.com)",
    "type": "plain"
   },

这就是它的打印方式

享受、点赞、评论、订阅 GiggleSquid 的 Twitter:https://twitter.com/GiggleSquidGigglesquid 的 Facebook:http://www.facebook.com/GiggleSquid GiggleSquid 和 dapaka 深入研究模拟城市,试图开发一个高效、繁华的大都市,他们会成功吗?不,可能不是 Outro Music:令人惊叹的 Kevin MacLeod 的独眼大师 (incompetech.com)

【问题讨论】:

标签: php youtube-api


【解决方案1】:

使用nl2br() PHP函数将\n转换为BR标签

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2021-12-04
    • 2012-06-25
    • 1970-01-01
    相关资源
    最近更新 更多