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

  • Home
  • SEARCH
  • 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 8194987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:59:15+00:00 2026-06-07T04:59:15+00:00

I am extremely new to json and have been working on this issue for

  • 0

I am extremely new to json and have been working on this issue for about a week.

I used php to retrieve tweets from a list of accounts and stored them into a .txt file

$cache = dirname(__FILE__) . '/../cache/twitter-json.txt';

$data = file_get_contents('http://api.twitter.com/1/lists/statuses.json?    slug=widget&owner_screen_name=webcodepro&count=1&page=1&per_page=8&include_rts=true&include_entities=true');    

    $cachefile = fopen($cache, 'wb');
    fwrite($cachefile,utf8_encode($data));
    fclose($cachefile);

?>

The way the architect has the front-end page structured is that I need to store the json value (what I have in the .txt file) into a json variable in a .js file and render it.

edit:
so it has been changed to

$cache =_ _DIR__.'/cached.txt'; 
$data = file_get_contents('http://api.twitter.com/1/lists/statuses.json?    slug=widget&owner_screen_name=webcodepro&count=1&page=1&per_page=8&include_rts=true&include_entities=true'); 

file_put_contents($cache, $data);

the file comes up empty. do you guys know what might be the problem?

Is it possible to store the contents of a .txt file into a json variable in a .js file?

  • 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-07T04:59:18+00:00Added an answer on June 7, 2026 at 4:59 am
    1. No need to utf8_encode things as JSON is already UTF-8
    2. You can simply use file_put_contents
    3. file_put_contents($cache, 'var myvar = '.$data.';');

    -edit-
    Code to clarify my solution:

    $cache = __DIR__.'/cached.txt';
    $data = file_get_contents('http://api.twitter.com/1/lists/statuses.json?slug=widget&owner_screen_name=webcodepro&count=1&page=1&per_page=8&include_rts=true&include_entities=true');
    file_put_contents($cache, 'var mydata = '.$data.';');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am EXTREMELY new to the html/php scene but I have been working at
I'm extremely new to JS and have this code that I'm trying to tweak.
I'm extremely new to Java, and have mostly just been teaching myself as I
I'm extremely new to Flex and I'm stuck at this early point. I have
I am extremely new to javascript and I have worked on this for hours....
Let me preface this by saying I am extremely new to git but have
I am extremely new to Java (just started this weekend) and have a background
I am extremely new to php and database. Suddenly I'm handed down this community
I'm extremely new to CakePHP. From what I've gathered, it seems like I can
Before I start know this: I am extremely new to Java and programming. How

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.