开发者

How to retrieve attribute of root element of DOMDocument? [duplicate]

This question already has an answer here: Closed 10 years ago.

Possible Duplicate:

DOMDocument::load - PHP - Getting attribute value

I use the following code:

$str = '<a href="some_link">text</a>';
$dom = new DOMDocument;
$dom->loadXML($str);

I want to obtain the value of root element of $str. In this example "some_l开发者_运维技巧ink" should be returned. In real case $str is read from file.

How to achieve this?


Try:

$dom->documentElement->getAttribute('%yourAttrName%');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜