How to check if a SimpleHTMLDom element does not exist

前端 未结 4 1048
忘了有多久
忘了有多久 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 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 */ }
    

提交回复
热议问题