php-html-parser icon indicating copy to clipboard operation
php-html-parser copied to clipboard

Find does not work with multiple attributes

Open richard-wolsch opened this issue 2 years ago • 0 comments

$dom->find(…) does not work with a CSS selector with multiple attributes.

Example:

        $testDom = new Dom();
        $testDom->loadStr('<div><input type="checkbox" name="color" value="blue"><input type="checkbox" name="color" value="red"></div>');
        $allCheckboxes = $testDom->find('input[name="color"]');
        echo count($allCheckboxes);  // 2 → that is fine
        $blueCheckbox = $testDom->find('input[name="color"][value="blue"]', 0);
        echo is_null($blueCheckbox); // true → Not good! I would expect the checkbox with value "blue" here.

Workaround: One could select just for the value $testDom->find('input[value="blue"]', 0); but this could of course find results with unwanted name-attributes too.

richard-wolsch avatar Jul 27 '23 11:07 richard-wolsch