if node value empty else

837 Views Asked by At

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';
}
?>
1

There are 1 best solutions below

0
Johan Venables On

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';
}
?>