<?php
$xmlstr = <<<XML
<sections>
  <section>
    <paragraph>
      <literal class="html">
        &lt;img alt="" src="http://a...content-available-to-author-only...e.org/empty.png" /&gt;&lt;/span&gt;&lt;/span&gt; Yes/no&amp;nbsp;&lt;br /&gt;
        &lt;img alt="" src="http://a...content-available-to-author-only...e.org/empty.png" /&gt;&lt;/span&gt;&lt;/span&gt; Other text/no&amp;nbsp;&lt;br /&gt;
      </literal>
    </paragraph>
  </section>
</sections>
XML;

$sections = new SimpleXMLElement($xmlstr);

foreach ($sections->section->paragraph as $paragraph) {
  $re = "~<img.*?>(?=</span)~";
  $subst = "<custom name=\"my_checkbox\"></custom>";
  $paragraph->literal = preg_replace($re, $subst, $paragraph->literal);
}

echo $sections->asXML();

?>
