|登录 |注册

查看: 2249|回复: 4
打印 上一主题 下一主题

PHP: simplexml_load_string(); 怎么用?

[复制链接]
宅男-兜着走
2009-7-7 03:18 PM
如果开错地方,请多多见谅。

我在FLASH 里生成了这个 XML.toString();

<theXML>
<index theName="my Name is 0" indexId="0" />
<index theName="my Name is 1" indexId="1" />
<index theName="my Name is 2" indexId="2" />
<index theName="my Name is 3" indexId="3" />
<index theName="my Name is 4" indexId="4" />
</theXML>

在PHP里:

<?PHP
$XML = stripslashes($_POST['XML']);
$root = simplexml_load_string($XML);
echo "&reply=$root->index->Attribute('indexId')";
?>

请问我哪里用错了? 出来的结果是 index-> attribute('indexId');  没这个 “ ” 的话就Error。

Fatal error: Call to a member function Attribute() on a non-object in C:\xampp\htdocs\eims\flashXML.php on line 11

[ 本帖最后由 宅男-兜着走 于 2009-7-7 03:52 PM 编辑 ]
Super-Tomato
2009-7-7 05:54 PM
原帖由 宅男-兜着走 于 2009-7-7 03:18 PM 发表
如果开错地方,请多多见谅。

我在FLASH 里生成了这个 XML.toString();









在PHP里:



请问我哪里用错了? 出来的结果是 index-> attribute('indexId');  没这个 “ ” 的话就Error。
...



//方法 1
<?PHP
$XML = stripslashes($_POST['xml']);
$root = simplexml_load_string($XML);
for($i=0; $i<count($root); $i++)
        echo "&reply=" . $root->index[$i]["indexId"] . "<br/>";
?>


//方法 2
<?PHP

$XML = stripslashes($_POST['xml']);
$root = simplexml_load_string($XML);
foreach($root as $child)
{
        list($theName, $indexId) = $child->attributes();
        echo "&reply=" . $indexId . "<br/>";
}
?>

[ 本帖最后由 Super-Tomato 于 2009-7-7 06:02 PM 编辑 ]

回复 #2 Super-Tomato 的帖子

宅男-兜着走
2009-7-7 06:28 PM
解决了,谢谢。 cari那个人也是你?
goodday
2009-7-7 09:12 PM
还好这几天有番茄
event很忙
Super-Tomato
2009-7-8 01:31 AM
原帖由 宅男-兜着走 于 2009-7-7 06:28 PM 发表
解决了,谢谢。 cari那个人也是你?



是不是我沒關係, 只要有人幫到你就好了


原帖由 goodday 于 2009-7-7 09:12 PM 发表
还好这几天有番茄
event很忙



我這幾天想偷懶就自己放假, 所以就比較多時間上來逛逛
您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2026-1-1 10:36 AM , Processed in 0.101635 second(s), 26 queries .

Powered by Discuz! X2.5 © 2001-2012 Comsenz Inc.

本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved

Dedicated Server powered by iCore Technology Sdn. Bhd.

合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部