Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8914405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:42:41+00:00 2026-06-15T04:42:41+00:00

I have this code: <?php header(‘Content-Type: text/javascript; charset=UTF-8’); header(‘Cache-Control: private, no-cache, no-store, must-revalidate’); header(‘Pragma:

  • 0

I have this code:

<?php

    header('Content-Type: text/javascript; charset=UTF-8');
    header('Cache-Control: private, no-cache, no-store, must-revalidate');
    header('Pragma: no-cache');
    header('Expires: Sat, 01 Jan 2000 00:00:00 GMT');

    $data = array(
        "data" => array(
            "sender" => "Jhon Andrew",
            "recipient" => "Someone OverThe Internet",
            "conversation" =>
            array(
                "unix" => "1234567890",
                "message" => "Lorem ipsum dolor sit amet."
            ),
            array(
                "unix" => "0987654321",
                "message" => "Tema tis rolod muspi merol."
            )
        )
    );

    echo json_encode($data);

?>

And I was expecting this kind of result:

{
    "data": {
        "sender":"Jhon Andrew",
        "recipient":"Someone OverThe Internet",
        "message":"Lorem ipsum dolor sit amet."
    }
}

But I got it displayed in just one line, like this:

{"data":{"sender":"Jhon Andrew","recipient":"Someone OverThe Internet","message":"Lorem ipsum dolor sit amet."}}

How can I get properly formatted JSON output just like what I am expecting? It’s not really important actually, but I just want to see the result in good format.


…by the way, I just copied the headers from facebooks graph link
because that is how I want to output the result. Example:
graph.facebook.com/mOngsAng.gA


It is valid of course. All I want to know is how to output it like
this: graph.facebook.com/mOngsAng.gA – As you can see it is properly
formatted. I mean it has line breaks and indentions. Unlike what I am
getting is just showed in one line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:42:42+00:00Added an answer on June 15, 2026 at 4:42 am

    Take a look at JSON_PRETTY_PRINT flag of json_encode() in php manual.
    You can simply use:

    $data = json_encode($data, JSON_PRETTY_PRINT);
    

    If you aren’t using PHP 5.4 or greater try with the accepted answer of the question: Pretty-Printing JSON with PHP.

    However, yours is a valid json output!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code on the server side: <?php header('Content-Type: text/html; charset=utf-8'); require ../general.variables.php;
I have this code <?php ob_start(); header(Content-Type: text/html; charset=ISO-8859-1); $campo = $_GET['campo']; $valor =
I have this code for an app i'm working on: <?php header(Content-type: text/xml); //Gather
I have made a code -- <?php header(Content-type: text/javascript); require_once('../php/config.php'); $domail_theme = $_GET['theme']; ?>
I have this code: <meta http-equiv=content-type content=text/html; charset=<?php echo $stigConfig['charset']; ?> /> How can
I have this code in PHP: header(Content-Type: application/vnd.ms-excel); header(Content-Type: application/download); header(Content-Length: .filesize($path.$filename)); header(Content-disposition: attachment;
I have this simple code in php: <?php header(Content-type: application/vnd.ms-word); header(Content-Disposition: attachment;Filename=kid_tag.doc); echo '<table
xss.php <?php header('Content-Type:text/html; charset=UTF-8'); var_dump(ini_get('filter.default')); if (isset($_GET['name'])) { echo $_GET['name']; exit(); } browsing http://localhost/xss.php?name=%3Cscript%3Ealert('XSS')%3C/script%3E
I have this PHP code and it works fine. header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename=WTBak.zip');
its a little bit hard to understand. in the header.php i have this code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.