Wrap All Image Tags In A String With Links
<p>Trying to automatically wrap all image tags within a field that's currently managed with CKEditor.  Would really like to handle it all with PHP.</p>

<p>So this would be an example of a field's random contents:</p>

<pre><code>&lt;p&gt;
    Intro text here&lt;br /&gt;
    &lt;img alt="sample desc" src="/images/example1.jpg" /&gt;
    Long article text here...
    &lt;img alt="sample desc" src="/images/example2.jpg" /&gt;
    Short article text here...
    &lt;img alt="sample desc" src="/images/example3.jpg" /&gt;
&lt;/p&gt;
</code></pre>

<p>And I would need to change the above code to this, wrapping each image tag with a link using a unique id, href matching the img's source and title matching alt text:</p>

<pre><code>&lt;p&gt;
    Intro text here&lt;br /&gt;
    &lt;a id="image1" href="/images/example1.jpg" title="sample desc"&gt;
       &lt;img alt="sample desc" src="/images/example1.jpg" /&gt;
    &lt;/a&gt;
    Long article text here...
    &lt;a id="image2" href="/images/example2.jpg" title="sample desc"&gt;
       &lt;img alt="sample desc" src="/images/example2.jpg" /&gt;
    &lt;/a&gt;
    Short article text here...
    &lt;a id="image3" href="/images/example3.jpg" title="sample desc"&gt;
       &lt;img alt="sample desc" src="/images/example3.jpg" /&gt;
    &lt;/a&gt;
&lt;/p&gt;
</code></pre>

<p>Thanks for any help you can provide!</p>
