Hi wonder if anyone could help me.
the first code below basically counted every XML record and outputted in a desired formatt
Old code
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://xxxxx');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml_string = curl_exec ($ch);
curl_close ($ch);
// parse data
$xml=simplexml_load_string($xml_string);
// fix to n slots, zero padded
$slots=6;
$counter = substr((string)(pow(10,$slots)+count($xml)),1,$slots);
for($c=0; $c<strlen($counter); $c++)
{
echo("<span>".$counter[$c]."</span>");
}
Out put
<span>1</span><span>3</span><span>5</span><span>6</span><span>8</span><span>8</span>
this was all ok but now the XML feed has changed and is just outputting the below.
<Data>
<Row>
<Column name="cam" type="xs:int">000</Column>
<Column name="camN" type="xs:string">hello</Column>
<Column name="numer" type="xs:int">1</Column>
</Row>
<Row>
<Column name="cam" type="xs:int">000</Column>
<Column name="camN" type="xs:string">hello</Column>
<Column name="numer" type="xs:int">985</Column>
</Row>
<Row>
<Column name="cam" type="xs:int">000</Column>
<Column name="camN" type="xs:string">hello</Column>
<Column name="numer" type="xs:int">1</Column>
</Row>
</Data>
i need the same output to happen but not sure how i take the number value from each record + them togther and then output them making sure i have 6 charactures even if it ends up 000005 as a value
Cheers
Update
sorry i need to add the numer values together to get a totel so if the totel is 987 i need it to output:
<span>0</span><span>0</span><span>0</span><span>9</span><span>8</span><span>7</span>
You can use xpath to grab the nodes you want, like so:
Now, to get your desired output, pad the number with zeroes, split it into chunks of 1 character, and output it, like so: