phpquery

how to get index of element in phpquery


I'm trying to get index of div which contains 'Shop Name' like:

$doc = phpQuery::newDocument($shops_page);
echo $shop_index = $doc->find(".shop_item:contains('Shop Name')")->index();

in JQuery $(".shop_item:contains('Shop Name')").index(); works

How can i find index using phpquery?


Solution

  • if ($doc->find(".shop_item:contains('Shop Name')")->length()){
    $shop_index = $doc->find(".shop_item")->index(pq($doc->find(".shop_item:contains('.shop_item:contains('Shop Name')')")));
    }