S
S
suhuxa12018-02-06 13:43:42
PHP
suhuxa1, 2018-02-06 13:43:42

How to cut an entire block of html using php?

Good afternoon!
I get the html code of a specific page. Inside there is this structure:

<div class="container">
  <div class="box">
    ..... (some code)
  </div>
  <div class="box">
    ..... (some code)
  </div>
  <div class="box">
    ..... (some code)
  </div>
  <div class="box">
    ..... (some code)
  </div>
</div>

How can I cut out the entire container block with all the content? Regular expressions come to mind, but I have no idea how to cut like this if our block ends with </div>, but before that, there is also </div>.
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
Justique, 2018-02-06
@suhuxa1

https://regex101.com/r/iIGpJV/1

$content = '<div class="container">
  <div class="box">
    ..... (some code)
  </div>
  <div class="box">
    ..... (some code)
  </div>
  <div class="box">
    ..... (some code)
  </div>
  <div class="box">
    ..... (some code)
  </div>
</div>';

preg_match("#<div class=\"container\">(.+?)\n<\/div>#is", $content, $res);

var_dump($res);

M
Maxim Timofeev, 2018-02-06
@webinar

simplehtmldom.sourceforge.net

O
Oleg, 2018-02-06
@402d

https://habrahabr.ru/post/69149/
and don't say it's junk ;) For those who have worked with JQuery selectors, it's easier or not

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question