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
精彩评论