I suppose there's probably a way, but it's going to be non-trivial. For example, what if your cut-off point was where the following text changes color?
<div>
<h2>Heading</h2>
<ul id='nav'>
<li><a href='one.php'>Item One</a></li>
<li><a hr[color=red]ef='two.php'>Item Two</a></li>
<li><a href='three.php'>Item Three</li>
</ul>
</div>[/color]
If the cut-off code is not smart enough to go all the way to the closing </div> tag, then you are going to end up with broken HTML. You would therefore somehow have to keep track of what tags are open, and determine at what point in the string they are all closed. This might be do-able via a preg_replace function using recursion in the regex, but that sort of thing tends to make my brain explode. 😉