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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:47:47+00:00 2026-05-25T21:47:47+00:00

First of all i want to apologize if this is the most basic question

  • 0

First of all i want to apologize if this is the most basic question ever! I’m not that good with php but i’m learning.

I can’t find a solution or even understand why it’s going wrong all the time. I do want to know why this is happening

I’m trying to get the two latest tweets from a twitter account. I don’t want to use massive (existing, i know) classes or codes which i don’t understand. So i tried the following myself:

 $timeline = "http://twitter.com/statuses/user_timeline.xml?screen_name=Mau_ries";
    $data = file_get_contents($timeline);
    $tweets = new SimpleXMLElement($data);

    $i = 0;
    foreach($tweets as $tweet){
        echo($tweet->text." - ".$tweet->created_at);
        if (++$i == 2) break;
    }

When i first ran this code i got the text from my tweets, but when i refreshed the page i sometimes get the following error:

Warning: file_get_contents(http://twitter.com/statuses/user_timeline.xml?screen_name=Mau_ries) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /path/to/file on line 88

Fatal error: Uncaught exception ‘Exception’ with message ‘String could not be parsed as XML’ in /public/sites/www.singledays.nl/tmp/index.php:89 Stack trace: #0 /public/sites/www.singledays.nl/tmp/index.php(89): SimpleXMLElement->__construct(”) #1 {main} thrown in /path/to/file on line 89

Lines 88 & 89 are these:

$data = file_get_contents($timeline);
$tweets = new SimpleXMLElement($data);

Really weird. Sometimes it work, sometimes not.

Does anybody know this issue and/or a solution? And why does the error seem to occur randomly (Allthough it;s now erroring for a while allready)?

Thanks!

  • 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-25T21:47:47+00:00Added an answer on May 25, 2026 at 9:47 pm
    $timeline = "http://twitter.com/statuses/user_timeline.xml?screen_name=Mau_ries";
    $data = @file_get_contents($timeline);
    
    if($data){
        $fh = fopen("cache/".sha1($timeline),"w");
        fwrite($fh, $data);
        fclose($fh);
    }else{
        $fh = @fopen("cache/".sha1($timeline),"r");
        $data = "";
        while(!feof($fh)){ $data = fread($fh, 1024); }
        fclose($fh);
    }
    
    if(!$data) die("could not open url or find a cache of url locally");
    
    $tweets = new SimpleXMLElement($data);
    
    $i = 0;
    foreach($tweets as $tweet){
        echo($tweet->text." - ".$tweet->created_at);
        if (++$i == 2) break;
    }
    

    There as every one has said debugging you should really cache the results in files and if it fails to download then use the cache the above code will do it for you.

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

Sidebar

Related Questions

This is very basic magento question i guess. I want to first get all
First of all, I want to be clear that I'm not talking about defining
first of all, sorry if that question is dumb but I´m a total newbie
First of all, I apologize if this is a stupid question, I'm a dead
First of all, let me apologize if this question is too broad. I'm looking
First of all, I want to apologize for such a long question. You don't
I apologize if this is a duplicate but I did not find anything that
I apologize because I am quite certain this is a basic question. All I
First of all, I don't want to use a join because that will make
First of all I don't know if this is the right approach. I want

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.