I've been using \K
quite a lot but recently realized that it does not work in PHP below v5.2.4. So I'm looking for a different way.
<?php
$html = '<div>hello</div>
<div class="someclass">hi</div>
<div class="sample">this text should be included</div>
<div>bye</div>
';
// $pattern = '/<div.+class=["\']sample["\'].+div>\K/i'; // <-- this doesn't work below v5.2.4
$pattern = '/(?<=<div.+class=["\']sample["\'].+div>)/i'; // causes an error.
$array = preg_split($pattern, $html);
print_r($array);
?>
I've seen somewhere (?<=)
can be used as the alternative and I tried it but it causes an error. Any suggestion?