How is it possible to get the highest existing guid value from an existing xml file (SimpleXml).
xml-structure example:
<xml blabla>
<blog name="">
<post>
<guid>3</guid>
<author></author>
<content>...</content>
</post>
<post>
<guid>1</guid>
<author></author>
<content>...</conte开发者_开发百科nt>
</post>
</blog>
I tried the following ($xml is an SimpleXml Object) max($xml->xpath(/blog/post/guid)); but this seems to be no array...
any suggestions? Is there an way to handle it per xpath? My google search wasn't successful.
You could use array_map('intval'... to feed max() with something it "understands".
<?php
$xml = getDoc();
$ns = $xml->xpath('//blog/post/guid');
$ns = array_map('intval', $ns);
echo max($ns);
function getDoc() {
return new SimpleXMLElement( <<< eox
<xml>
<blog name="">
<post>
<guid>3</guid>
<author></author>
<content>...</content>
</post>
<post>
<guid>1</guid>
<author></author>
<content>...</content>
</post>
<post>
<guid>99</guid>
<author></author>
<content>...</content>
</post>
<post>
<guid>47</guid>
<author></author>
<content>...</content>
</post>
</blog>
</xml>
eox
);
}
精彩评论