I'm using a PHP function to split text into blocks of max N chars. Once each block is "treated" somehow, it is concatenated back again. The problem is that the text can be HTML... and if the split occurs between open html tags, the "treatment" gets spoiled. Can someone give a hint about breaking text only between closed tags?
Requirements:
- Max block length: N
- There are NO
<body>
tags - There are NO
<HTML>
tags - There are NO
<head>
tags
Adding a sample: (max block length = 173)
<div class="myclass">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer dapibus sagittis lacus quis cursus.
</div>
<div class="anotherclass">
Nulla ligula felis, adipiscing ac varius et, sollicitudin eu lorem. Sed laoreet porttitor est, sit amet vestibulum massa pretium et. In interdum auctor nulla, ac elementum ligula aliquam eget
</div>
In the text above, given 173 chars as the limit, text would break @ "adipiscing", however that would break the <div class="anotherclass">
. In this case, the split shall occur at the first closing, although being shorter the the max limit.