M
M
mirexdoors2018-03-28 18:25:04
PHP
mirexdoors, 2018-03-28 18:25:04

How to parse html code?

Hello! There is the following code:

...
<div class="issue">
            <h2 class="notop">***</h2>
            <div class="grid_2 alpha alcenter download_issue">
              <a href="***"><img src="images/download_pdf.png"/></a><br />
              PDF, 10 Мб
            </div>
            <div class="grid_10 omega">
              текст
            </div>
          </div>

It is necessary by means of php (simple html dom?) to parse the code that is located inside the div with the "issue" class.
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-03-28
@mirexdoors

You can use Zend\Dom\Query

use Zend\Dom\Query;

$dom = new Query($html);
$nodes = $dom->execute('div.issue');
foreach ($nodes as $node) {
    // $node is a DOMElement http://php.net/manual/ru/class.domelement.php
    echo $node->C14N();
}

And the simple html dom hasn't been updated in years, so I wouldn't bother.
From a more complex one, you can take Guzzle , where the http client is immediately included.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question