Johan Venables
Johan Venables

Reputation: 57

if node value empty else

I have following code but even if node value is empty or populated I get same echo = is not set or empty

In my header I include XML file which include :

 $linkwebsite = $element->getElementsByTagName('linkwebsite')->item(0) ;

PHP Code:

<?php
    if (!empty($linkwebsite)){
    echo 'not empty';
}
else{
    echo 'is not set or empty';
}
?>

Upvotes: 0

Views: 871

Answers (1)

Johan Venables
Johan Venables

Reputation: 57

Ok got it when I echo variable got error - Object of class DOMElement could not be converted to string so I had to set variable node value as follow

<?php
if (!empty($linkwebsite->nodeValue)){
echo 'not empty';
}
else{
echo 'is not set or empty';
}
?>

Upvotes: 0

Related Questions