开发者

Object of class DOMElement could not be converted to string

I try to parse an XML rss flux. Actually, an error is thrown:

Catchable fatal error: Object of class DOMElement could not be converted to string in ...

I want to get the value "test" of the tag "link"

Here is my code :

//check if url contents xml
            $content = file_get_contents($flux);

            $xml = new DOMDocument;
            $xml->loadXML($content);

            //get the link
            $link = $xml->getElementsByTagName('link')->item(0);

            echo $link;

Here is the flux :

<?xml version="1.0" encoding="ISO-8859-15" ?>
<rss version="2.0">
    <channel>
        <title>test</title>
        <link>http://test.fr</link>
    </channel>
</开发者_开发问答rss>

Anyone can help me ?


$link is an object which can not be converted to string (some objects can).

To see which object it is, use var_dump($link);. I assume it's a DOMElementDocs, see the link for all properties and methods it has to offer, e.g.

echo $link->tagName;

or

echo $link->textContent;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜