PHP - accesing and modyfing data "on the fly"?
<p>Imagine you have a .php code:</p>

<pre><code>    &lt;ul&gt;
       &lt;li&gt;&lt;?php smth ?&gt;&lt;/li&gt;
       &lt;li&gt;&lt;?php smth ?&gt;&lt;/li&gt;
       &lt;li&gt;&lt;?php smth ?&gt;&lt;/li&gt;
    &lt;ul&gt;

    &lt;ul&gt;
       &lt;li&gt;&lt;?php smth ?&gt;&lt;/li&gt;
       &lt;li&gt;&lt;?php smth ?&gt;&lt;/li&gt;
       &lt;li&gt;&lt;?php smth ?&gt;&lt;/li&gt;
    &lt;ul&gt;

(...)
</code></pre>

<p>But the the code is dynamically generated and loaded in one function and there's no direct access to each nodes (&lt; li > in this case). So on my site it looks a bit like include:</p>

<pre><code>&lt;?php include("but not the file but code above generated by some engine"); ?&gt;
</code></pre>

<p>All clear? So here's the deal.</p>

<p>I want to modify this code. So after it loads I want each &lt; ul > element to be inside of a div with increasing ID. So the end code will look like:</p>

<pre><code> &lt;div id="1"&gt;
     &lt;ul&gt;
               &lt;li&gt;&lt;?php smth ?&gt;&lt;/li&gt;
               &lt;li&gt;&lt;?php smth ?&gt;&lt;/li&gt;
               &lt;li&gt;&lt;?php smth ?&gt;&lt;/li&gt;
     &lt;ul&gt;
   &lt;/div&gt;

&lt;div id="2"&gt;

      &lt;ul&gt;
               &lt;li&gt;&lt;?php smth ?&gt;&lt;/li&gt;
               &lt;li&gt;&lt;?php smth ?&gt;&lt;/li&gt;
               &lt;li&gt;&lt;?php smth ?&gt;&lt;/li&gt;
      &lt;ul&gt;
&lt;/div&gt;
(...)
</code></pre>

<p>Any ideas? I have my own concept based on stripping site's code after loading and adding divs with for loop but I believe there's more elegant way?</p>
