Formatting json contents output

This question already has an answer here:

  • Pretty-Printing JSON with PHP 20 answers

  • I am assuming that you are displaying "HTML" to the user and the formatting that you wish to show is in HTML, then n wont cause new lines... use " <br/>" .

    And then your single and double quotes wont matter, either.


    尝试将您的新行字符转换为<br> HTML元素,因为无论您用于解析并显示JSON,显然都不会遵守n新行:

    $displaystring = nl2br($displaystring);
    

    $displaystring = "Welcome to Polio Buddy. Please select.n <a href="register.php">1 : Register Family</a>n <a href="check.php">2: Check Vaccination Status</a>n <a href="vaccinate.php">3: Vaccinate Child</a>";
    

    PHP can interpret strings with double quotes or leave as it when you have single. my custom variable string print 'nt $variable"; // will output unchanged nt $variable

    BTW: Whenever it's possible it's better to use single quotes, as PHP don't waste resources for interpreting if there are any variables to output.

    链接地址: http://www.djcxy.com/p/47274.html

    上一篇: Laravel 4 JSON输出格式

    下一篇: 格式化json内容输出