开发者

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

开发者 https://www.devze.com 2023-03-30 03:18 出处:网络
This question already has an answer here: Closed 10 years ago. Possible Duplicate: DOMDocument::load - PHP - Getting attribute value
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

精彩评论

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