i'd like to split a long text into chunks. I need to split by element class (element can be h, p, span, div or others unknown tag). So, for example, if I got a string like:
$string = 'Hi this is a long <span class="cut">string</span> and I need to <span class="cut">split it into chunks</span> and I need help for <span class="cut">this</span>';
I'd like to split by cut class, into array, keeping all texts:
Expected result:
$array(
0 => 'Hi this is a long ',
1 => '<span class="cut">string</span>',
2 => ' and I need to ',
3 => '<span class="cut">split it into chunks</span>',
4 => ' and I need help for ',
5 => '<span class="cut">this</span>'
);
I don't find any example on the web.
I find only this one by it find only elements by class and exclude all other text and I don't know if it is usefull for my purpose:
$domdocument = new DOMDocument();
$domdocument->loadHTML($contenuto);
$a = new DOMXPath($domdocument);
$elements = $a->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' cut')]");
for ($i = $elements->length - 1; $i > -1; $i--) {
var_dump($elements->item($i)->firstChild->nodeValue);
}