You are here: Re: Array length in SimpleXML « PHP Programming Language « IT news, forums, messages
Re: Array length in SimpleXML

Posted by petersprc on 11/25/06 03:45

Hi,

Try maybe:

echo "There are " . count($xml->xpath('/items/item')) . " top-level
items.\n";

lhenkel@gmail.com wrote:
> This is idiotic, but I can't figure this out:
>
> I can do this:
> $xml = new SimpleXMLElement('<items>
> <item><name>Lee</name><count>1</count></item>
> <item><name>Bill</name><count>5</count></item></items>');
> foreach ($xml->item as $item) {
> echo $item->name, '<br />';
> }
>
> But I can't figure how to tell I have 2 items. The obvious:
>
> print count($xml->item); // same for $xml->items
> and
> print $xml->item->length; // same for $xml->items->length
>
> They don't work the way I expect..
>
> This is my first foray into XML, so I'm sure I'm doing something
> stupid.. would anyone mind pointing it out?
>
> Thanks,
>
> Lee

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация