简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM