Search code examples
phpsimple-html-dom

How to use find method in simple html dom when have multiple classes


If I have an element something like this

<h1 class="first second last">
    <p>Paragraph</p>
</h1>

I want to use find method only for these three classes. I tried like this :

$html->find('first.second.last',0)->plaintext;

But it's not working. Is there any idea to use find method for this type of condition?


Solution

  • test.html :

    <h1 class="first second last">
        <p>Paragraph</p>
    </h1>
    

    As I had to it in php simple html dom parser. I found a alternate solution for my query not by using find method but we can check multiple classes by using this:

    include "simple_html_dom.php";
    
    $html = file_get_html('test.html');
    $h1 = $html->find('h1');
    foreach ($h1 as $h1) {
        $h1Class = ($h1->class);
        if($h1Class == 'first second last'){
            $item['test'] = 'success';
        }else{
            $item['test'] = 'fail';
        }
        $ar[] = $item;
    }
    echo "<pre>";
    print_r($ar);