GiggleSquid
GiggleSquid

Reputation: 5

Formatting embedded YouTube video descriptions

I've got a PHP function that gets my latest YouTube video from the API, I can access the description, but it's not formatted i.e. it's basically one line of text, is there a way to make the \n actually print a new line?

This is the function

    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;
}

And this is the description directly from the 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"
   },

And this is how it prints

Enjoy, Like, Comment, Subscribe GiggleSquid's Twitter: https://twitter.com/GiggleSquid Gigglesquid's Facebook: http://www.facebook.com/GiggleSquid GiggleSquid and dapaka delve into SimCity in a hopeless attempt to develop an efficient, bustling metropolis, will they succeed? No, probably not Outro Music: One-eyed Maestro by the amazing Kevin MacLeod (incompetech.com)

Upvotes: 0

Views: 341

Answers (1)

Paul Denisevich
Paul Denisevich

Reputation: 2414

Use nl2br() PHP function to convert \n into BR tag

Upvotes: 1

Related Questions