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 7177943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:49:08+00:00 2026-05-28T16:49:08+00:00

I am using the file_get_contents function in php to get the contents of a

  • 0

I am using the file_get_contents function in php to get the contents of a site. The problem is that on the site I am grabbing information from, the information is neatly indented, yet when I retrieve the information it looses all indentation.

The code I am using is:

<?php
$url = "https://graph.facebook.com/btaylor";
$file = file_get_contents($url);
echo "$file";
?>

If you go to the original site here, you can see how the information is set up as:

{
   "id": "220439",
   "name": "Bret Taylor",
   "first_name": "Bret",
   "last_name": "Taylor",
   "link": "https://www.facebook.com/btaylor",
   "username": "btaylor",
   "gender": "male",
   "locale": "en_US"
}

yet on my site, after grabbing the information it looks like this:

{"id":"220439","name":"Bret Taylor","first_name":"Bret","last_name":"Taylor","link":"http:\/\/www.facebook.com\/btaylor","username":"btaylor","gender":"male","locale":"en_US"}

How can I keep the indentation?

Thanks in advance!

By the way, the link and information is from a sample page from Facebook, and not real information.

  • 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-05-28T16:49:09+00:00Added an answer on May 28, 2026 at 4:49 pm

    This has nothing to do with file_get_contents. It solely depends on the Content-Type of your page. The original is plain text, while your site outputs HTML.

    You can either use:

     header("Content-Type: text/plain");
    

    Or keep the HTML type but wrap your output in pre tags:

     echo "<pre>$file</pre>";
    

    Since you possibly want to reuse that mirrored JSON output, I would go for the first option. (But then an application/json type might be more appropriate. Not sure why you want to present it with fixed formatting anyway.)

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

Sidebar

Related Questions

Thanks in advance. Getting this warning when using below code: Warning: file_get_contents(test.php) [function.file-get-contents]: failed
I'm using PHP's function file_get_contents() to fetch contents of a URL and then I
We've been using information from a site for a while now (something that the
I am using the PHP function file_get_contents to read and display the contents of
I am using the file_get_contents function to get the URL into a string: $contents
I get a page using file_get_contents from a remote server, but I want to
I am using System.IO.FIle.ReadAllText() to get the contents of some template files that I
Hi We have some php code using the file_get_contents() function, and I understand this
All the strings on my site are pulled from a php language function named
I am using php 5.2 and I am fetching data from url using file_get_contents

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.