用PHP回显XML文件内容

用PHP回显XML文件内容,php,xml,xmltable,Php,Xml,Xmltable,我想使用file\u get\u contents($XML)以简单的表格格式回显以下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"

我想使用
file\u get\u contents($XML)
以简单的表格格式回显以下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>
看看这个

$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'];
}
$xmltext='1
真的
';
$xml=simplexml\u load\u字符串($xmltext);
foreach($xml->Calls->callas$Call)
{
$attributes=$call->attributes();
echo$attributes['StartTime'];
}

我认为您可以改进此代码示例并完成您的工作。

我尝试过:$calls=file\u get\u contents($xml\u url)$xml\u calls=simplexml\u load\u字符串($calls);echo$xml_calls->calls;上面这张没有打印任何东西…谢谢Prasad。。。。我尝试了你的想法…但无法按照我想要的方式格式化,如果你能解释更多以使其步入正轨,我将不胜感激,特别是在主要问题中要求的格式。。。对不起,我不是一个真正的极客类型…lollSee这个。它解释了如何创建动态表。
$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'];
}