【发布时间】:2012-09-04 10:43:15
【问题描述】:
可能重复:
SimpleXML: How to find number of children of top-level element?
php count xml elements
我有这个代码:
$string = <<<XML
<?xml version='1.0'?>
<document>
<title>Forty What?</title>
<from>Joe</from>
<to>Jane</to>
<body>
I know that's the answer -- but what's the question?
</body>
</document>
XML;
$xml = simplexml_load_string($string);
$data_count = count($data->xml);
print_r($data_count);
我在Demo线上运行这段代码
当我执行print_r($data_count); 时,结果是“0”而不是 10(字符串中的行);
我应该怎么做才能在变量 $data_count 中包含原始数字?
非常感谢。
【问题讨论】:
-
instead 10(rows in the string);是什么意思 -
以及相关部分中的更多内容。提问前请使用搜索功能。当我们要求您在stackoverflow.com/questions/ask-advice 中做作业时,我们是认真的
-
"结果 [原文如此] 是 "0" 而不是 10(字符串中的行);" — 我很难看到你有 10 个,你能解释一下什么是“行”?