How to balance tags with PHP
<p>In the string below, I want to replace <code>&lt;!--more--&gt;</code> with some text, <code>FOOBAR</code>, then truncate the string.</p>

<pre><code>&lt;p&gt;The quick &lt;a href="/"&gt;brown&lt;/a&gt; fox jumps &lt;!--more--&gt;
over the &lt;a href="/"&gt;lazy&lt;/a&gt; dog.&lt;/p&gt;
</code></pre>

<p>I've got to this point:</p>

<pre><code>&lt;p&gt;The quick &lt;a href="/"&gt;brown&lt;/a&gt; fox jumps FOOBAR
</code></pre>

<p>... but as you can see, the <code>&lt;p&gt;</code> tag is not closed. Any ideas on how I could consistently balance the tags? I am pretty new to PHP.</p>

<p>The array I am working with looks like this:</p>

<pre><code>array(2) {
  [0]=&gt;
  string(50) "&lt;p&gt;The quick &lt;a href="/"&gt;brown&lt;/a&gt; fox jumps "
  [1]=&gt;
  string(45) " over the &lt;a href="/"&gt;lazy&lt;/a&gt; dog.&lt;/p&gt;"
}
</code></pre>
