M
M
magogo2019-03-30 07:38:31
PHP
magogo, 2019-03-30 07:38:31

How to cut a div block?

$string ='
<div class="one">
      <p>sdfg</p>
      <p>sdfg</p>
      <p>sdfg</p>

      <div class="two">
         <p>sdfg</p>
         <p>sdfg</p>
      </div>
</div>';

function parse($p1, $p2, $p3) {
    $num1 = strpos($p1, $p2);
    $num2 = substr($p1, $num1);
    return substr($num2, 0, strpos($num2, $p3));
}

echo parse($string, '<div class="one">', '</div>');

You need to cut out the entire block with the class "one", the problem is that there may be other divs inside this block.
So I started, but I don't know what to do next ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
netrox, 2019-03-30
@netrox

https://github.com/paquettg/php-html-parser
https://github.com/symfony/dom-crawler

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question