Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 951
Raphaël Avatar asked Oct 04 '11 13:10

Raphaël


1 Answers

$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;
like image 182
hakre Avatar answered Sep 21 '22 12:09

hakre