문제

Hi pretty basic question that I'm surprised wasn't already asked here.

Is it possible to directly get an element based on an id, using Querypath?

Currently, the way I do it is

$qp = htmlqp('../index.php');
foreach ($qp->find('img') as $key) {

    if ($key -> attr('id') === "$picID") {
        $src = $key -> attr('src', $src) -> writeHTML("../indextest.php");
    }
}

however this does not seem to be the most efficient method as it loops through every image each time, when it could just access the ID directly.

도움이 되었습니까?

해결책 2

Found the answer here.

It's just

$qp->find('#my-ID');

다른 팁

I think you can use getElementById function of XPath http://www.php.net/manual/en/domdocument.getelementbyid.php

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top