dfcode3
dfcode3

Reputation: 809

Line break from json to PHP

I'm working with the following json code examples:

http://itunes.apple.com/lookup?id=434290957

http://itunes.apple.com/lookup?id=284910350

How can I get the line breaks in the description to appear in PHP? I think every \n is a line break. Here's my code thus far. Thanks for the help!

<?php

    $ch = curl_init('http://itunes.apple.com/lookup?id=434290957');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $content = curl_exec($ch);
    curl_close($ch);

    $contentdecoded = json_decode($content,true);
    foreach($contentdecoded['results'] as $item) {
        echo $item['kind'] ."<br>";
        echo $item['description'] ."<br>"; 
    }


?>

Upvotes: 0

Views: 1509

Answers (1)

miku
miku

Reputation: 188034

If you use text/html as MIME type (e.g. on a web page) you'll need to convert the newlines to linebreaks. PHP has a builtin for that: nl2br.

nl2br — Inserts HTML line breaks before all newlines in a string

Upvotes: 2

Related Questions