Jump to content

Php Getattribute Length


tinfanide
 Share

Recommended Posts

<?xml version="1.0" encoding="utf-8"?><root><name ######="M" age="15">Tin</name><name ######="F" age="13">Valerie</name><name ######="F" age="14">Valeriana</name><person name="Tin" ######="M" age="15" /></root>

Is there a way to get the attribute length in PHP?

<?php echo sizeof($xml->name); echo '<br />';echo sizeof($xml->name->attributes());  ?>

!!!The word '######' has just been renamed as #### by the siteBut that doesn't matter.!!! I've used simpleXML (confusing...unlike JScript) and tried to use sizeof();It works for tagNames and attributes within a tagName, But if I want to get the length of the attribute 'age' across the xml doc,is it possible?

Edited by Tin
Link to comment
Share on other sites

First ensure what$xml->name->attributes() is returning. it suppose to be return a simplexmlelement object which you need to iterate using loops when you will get the value you can then calculate the length of that using sizeof()http://in2.php.net/m....attributes.php if you are looking for similarity with js you may like to see http://in2.php.net/m...n/book.dom.php. which more versetile and more similar to DOM implmention of js

Edited by birbal
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...