Php 如何计算xml文件的原始元素?
可能重复:Php 如何计算xml文件的原始元素?,php,xml,Php,Xml,可能重复: 我有这个密码: $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 questi
我有这个密码:
$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);
$string=您应该试试
$xml = simplexml_load_string($string);
print_r($xml->count()); // 4
试试这个
$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($xml);//here you need to give the parser object
print_r($data_count);
echo count($xml->title); //No of title tags
$string=您也可以这样尝试:
<?php
$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";
$array = explode( "\r", $string );
print_r( sizeof( $array ) );
?>
10(字符串中的行)是什么意思代码>以及相关部分中的更多内容。询问前请使用搜索功能。当我们要求你在“ResAlt[sic]是“0”而不是“10”(字符串中的行);”中做作业时,我们真的是认真的。我正在努力看你有10行,你能解释一下“行”是什么吗?致命错误:调用/homepages/26/d94605010/htdocs/lz/writecodeonline.com/php/index.php(201):eval()中未定义的方法simplexmlement::count()第16行的d代码您使用的是什么版本的PHP。。这里有一个现场演示:它可以工作