PHP 8.5.0 Alpha 1 available for testing

Voting

: two plus three?
(Example: nine)

The Note You're Voting On

cryonyx at cerebrate dot ru
16 years ago
In case you have a XML file with a series of equally named elements on one level simplexml incorrectly processes them and doesn't allow to walk through the array using foreach(). As far as I'm concerned, it is the problem caused by PHP xml_parser (see: http://ru2.php.net/manual/ru/function.xml-parser-create.php#53188).

To avoid this, just use count() and walk through the array using for().

Example:

<params>
<param>
<name>version.shell</name>
<value>1.0</value>
</param>
<param>
<name>version.core</name>
<value>1.0</value>
</param>
<param>
<name>file.lang</name>
<value>vc.lang</value>
</param>
...
</params>

<?php
$filename
= '...';
$xml = simplexml_load_file($filename);
$p_cnt = count($xml->param);
for(
$i = 0; $i < $p_cnt; $i++) {
$param = $xml->param[$i];
...;
}
?>

<< Back to user notes page

To Top