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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:23:25+00:00 2026-06-08T17:23:25+00:00

I’m pretty new to coding and wanted to try and build a twitter app

  • 0

I’m pretty new to coding and wanted to try and build a twitter app for my website. I got the following code to work, but I know there is a better way of doing it… I just don’t know how (possibly printing out the data into an array and then into a table with a foreach statement?). I’d really appreciate if someone can point me in the right direction. Basically, what I’m looking to do is parse the XML and create variables that I can call/print out automatically instead of having to do it so manually (the way I’m doing it now).

Thanks!

<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.css" />
<title> Some Title </title>
</head>
<body>
<div class="container">
    <div class="row-fluid">
    <div class="span2">
        <!--Sidebar content-->
        <button>Carmelo Anthony</button>
    </div>
    <div class="span10">
        <!--Body content-->
        <?php
        $xmldata = 'https://twitter.com/statuses/user_timeline/carmeloanthony.xml';
        $open = fopen($xmldata, 'r');
        $content = stream_get_contents($open);
        fclose($open);
        $xml = new SimpleXMLElement($content);
        ?>
            <table class="table table-striped">
                <tr>
                    <td> <img src=" <? echo $xml->status[0]->user->profile_image_url; ?>"/> </td>
                    <td><strong> <? echo $xml->status[0]->user->name; ?></strong> <i>@<? echo $xml->status[0]->user->screen_name; ?></i> <br /> <? echo $xml->status[0]->text; ?></td>  
                    <td><? echo date("M j",strtotime($xml->status[0]->created_at)); ?></td>
                </tr>
                <tr>
                    <td> <img src=" <? echo $xml->status[1]->user->profile_image_url; ?>"/> </td> 
                    <td><strong> <? echo $xml->status[1]->user->name; ?></strong> <i>@<? echo $xml->status[1]->user->screen_name; ?></i> <br />  <? echo $xml->status[1]->text; ?></td>
                    <td><? echo date("M j",strtotime($xml->status[1]->created_at)); ?></td>
                </tr>
                <tr>
                    <td> <img src=" <? echo $xml->status[2]->user->profile_image_url; ?>"/> </td> 
                    <td><strong> <? echo $xml->status[2]->user->name; ?></strong> <i>@<? echo $xml->status[2]->user->screen_name; ?></i> <br />  <? echo $xml->status[2]->text; ?></td>
                    <td><? echo date("M j",strtotime($xml->status[2]->created_at)); ?></td>
                </tr>
                <tr>
                    <td> <img src=" <? echo $xml->status[3]->user->profile_image_url; ?>"/> </td> 
                    <td><strong> <? echo $xml->status[3]->user->name; ?></strong> <i>@<? echo $xml->status[3]->user->screen_name; ?></i> <br />  <? echo $xml->status[3]->text; ?></td>
                    <td><? echo date("M j",strtotime($xml->status[3]->created_at)); ?></td>
                </tr>
                <tr>
                    <td> <img src=" <? echo $xml->status[4]->user->profile_image_url; ?>"/> </td> 
                    <td><strong> <? echo $xml->status[4]->user->name; ?></strong> <i>@<? echo $xml->status[4]->user->screen_name; ?></i> <br />  <? echo $xml->status[4]->text; ?></td>
                    <td><? echo date("M j",strtotime($xml->status[4]->created_at)); ?></td>
                </tr>
            </table>
    </div>
</div>
</body>
</html>
  • 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-08T17:23:26+00:00Added an answer on June 8, 2026 at 5:23 pm

    You can use a foreach loop for this:

        <!-- ...html code... -->
        <?php
        $xmldata = 'https://twitter.com/statuses/user_timeline/carmeloanthony.xml';
        $open = fopen($xmldata, 'r');
        $content = stream_get_contents($open);
        fclose($open);
        $xml = new SimpleXMLElement($content);
        ?>
            <table class="table table-striped">
                <?php
                foreach($xml->status as $status)
                { ?>
                <tr>
                    <td> <img src=" <?php echo $status->user->profile_image_url; ?>" /> </td>
                    <td><strong> <?php echo $status->user->name; ?></strong> <i>@<?php echo $status->user->screen_name; ?></i> <br /> <?php echo $status->text; ?></td>  
                    <td><?php echo date("M j",strtotime($status->created_at)); ?></td>
                </tr>
                  <?php
                }
                ?>
            </table>
            <!-- rest of the code... -->
    

    For reference: http://php.net/manual/en/control-structures.foreach.php

    EDIT

    For the weird character problem, try decoding the string using : html_entity_decode

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.