My code is very very simple, I just have this:
$element = simpl开发者_JS百科exml_load_string($data);
print_r($element);
which prints out:
SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => addy'+r+'
[id] => addy'+r+'
[cols] => 45
[rows] => 2
[disabled] => disabled
)
[0] => '+url[r]+'
)
Is there anyway I can put the attributes array in a for() loop so that I can add the key/value pairs however and wherever I want on my page?
Use the SimpleXMLElement::attributes()
method
$attributes = $element->attributes();
foreach ($attributes as $attr => $val) {
// tada
}
精彩评论