开发者

Line break from json to PHP

开发者 https://www.devze.com 2023-03-15 14:17 出处:网络
I\'m working with the following json code examples: http://itunes.apple.com/lookup?id=434290957 http://itunes.apple.com/lookup?id=284910350

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_RE开发者_如何学JAVATURNTRANSFER, 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>"; 
    }


?>


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

0

精彩评论

暂无评论...
验证码 换一张
取 消