开发者

View the attributes array

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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜