How to check if a SimpleHTMLDom element does not exist

前端 未结 4 1052
忘了有多久
忘了有多久 2021-01-18 15:16

SimpleHtmldom can be used to extract the contents of the first element with class description.

$html = str_get_html($html);
$html->find(\'.d         


        
相关标签:
4条回答
  • 2021-01-18 15:53
    $avalable = ($element->find('span.sold-out-text', 0)) ? 1 : 0;
    

    It works for me.

    0 讨论(0)
  • 2021-01-18 16:04

    for me none of above solution worked and finally i checked like this

    $html = str_get_html($html);
    
    if($html){
        //html found
    }else{
        //html not found
    }
    
    0 讨论(0)
  • 2021-01-18 16:06

    According to the SimpleHtmlDOM Api str_get_html($html) expects a string as input. First check with a html validator if your code is well formatted.

    $htmlObj = str_get_html($html);
    if (!is_object($htmlObj)) return; // catch errors 
    
    // or wrap further code in 
    if (is_object($htmlObj)) { /* doWork */ }
    
    0 讨论(0)
  • 2021-01-18 16:16
    if(($html->find('.description', 0))) {
        echo 'set';
    }else{
        echo 'not set';
    }
    

    http://www.php.net/manual/en/control-structures.if.php

    0 讨论(0)
提交回复
热议问题