Z
Z
zhdoon2018-03-08 17:20:13
PHP
zhdoon, 2018-03-08 17:20:13

How to set selector in php-html-parser?

There is a library https://github.com/paquettg/php-html-parser/
The search for an html block with the desired id is searched like this:

$dom = new Dom;
$dom->loadFromFile('tests/big.html');
$contents = $dom->find('#block-id');

We have html code:
<div id="project1"></div>
<div id="project2"></div>
<div id="project3"></div>
<div id="project4"></div>

How to iterate over blocks in a loop, how to pass a selector? The code below doesn't work:
for($i = 0; $i < 5; $i++){
$contents = $dom->find('#project' . $i);
}

If set explicitly, in the form $contents = $dom->find('#project1' ), then it searches.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zim32, 2018-03-16
@zim32

Maybe the problem is in the index which is from scratch?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question