0

I want to echo the following XML file in a simple table format using file_get_contents($xml)...

<CallOverview>
<Calls Count="3">
<Call StartTime="10:26:25  (UTC)" Destination="+12345" Duration="00:02:25" Charge="0.039"/>
<Call StartTime="10:22:04  (UTC)" Destination="+12345" Duration="00:01:20" Charge="0.026"/>
<Call StartTime="10:08:28  (UTC)" Destination="+12345" Duration="00:02:24" Charge="0.039"/>
</Calls>
<MoreData>True</MoreData>
</CallOverview>

Simple table format to be converted into...

Calls Count: 3

Start Time    Destination    Duration    Charge
10:26:25      +12345         00:02:25    0.039
10:22:04      +12345         00:01:20    0.026
10:08:28      +12345         00:02:24    0.039
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
sohal07
  • 440
  • 8
  • 21
  • I tried: $calls = file_get_contents($xml_url); $xml_calls = simplexml_load_string($calls); echo $xml_calls->Calls; This above prints nothing... – sohal07 Aug 23 '12 at 01:14

1 Answers1

0

Check this.

$xmltext = '<CallOverview>
                <Calls Count="3">
                <Call StartTime="10:26:25  (UTC)" Destination="+12345" Duration="00:02:25" Charge="0.039"/>
                <Call StartTime="10:22:04  (UTC)" Destination="+12345" Duration="00:01:20" Charge="0.026"/>
                <Call StartTime="10:08:28  (UTC)" Destination="+12345" Duration="00:02:24" Charge="0.039"/>
                </Calls>
                <MoreData>True</MoreData>
                </CallOverview>';
$xml = simplexml_load_string($xmltext);
foreach($xml->Calls->Call as $call)
{
    $attributes = $call->attributes();
    echo $attributes['StartTime'];
}

I think you can improve this code sample and get done your work.

Prasad Rajapaksha
  • 6,118
  • 10
  • 36
  • 52
  • Thanks Prasad.... I tried your idea...but couldn't format it the way I exactly want to, I'll appreciate if you can explain bit more to bring it on track, specially in the formatting requested in the main question... sorry m not really a geek type...loll – sohal07 Aug 23 '12 at 17:34
  • See this. http://stackoverflow.com/questions/7885871/creating-a-dynamic-table-with-php It explains how to create dynamic table. – Prasad Rajapaksha Aug 24 '12 at 02:14