I'm using Joomla 1.5 and also have replicated the mod_mainmenu to produce a custom menu module. Recption menus has submenu products (inner UL tags). Here the menu's HTML:

<ul id="sub-menu">
    <li class="parent item10"><a href="link1.php"><span>Arts</span></a>
        <ul>
            <li class="item29">
                <a href="link2.php"><span>Arts Show</span></a></li>
            <li class="item29">
                <a href="link3.php"><span>Another Arts Show</span></a></li>
        </ul>
    </li>
    <li class="parent item15"><a href="link6.php"><span>News</span></a>
        <ul>
            <li class="item18">
                <a href="link7.php"><span>News Show</span></a></li>
        </ul>
    </li>
</ul>

I have to go ahead and take above HTML and rewrite it to appear such as this before it reaches the page:

<div id="sub-menu">
    <h3 class="parent item10"><a href="link1.php"><span>Arts</span></a></h3>
    <div>
       <a class="item29" href="link2.php"><span>Arts Show</span></a><br />
       <a class="item29" href="link3.php"><span>Another Arts Show</span></a>
    </div>
    <h3 class="parent item15"><a href="link6.php"><span>News</span></a></h3>
    <div>
       <a class="item18" href="link7.php"><span>News Show</span></a>
    </div>
</div>

How can you do that in PHP? Thanks.

PHP includes a Document Object Model class which can be used as this purpose.

However it might be a good deal simpler to simply alter the template that drives the output in Joomla making the modification at its source.

Since jQuery UI Accordion don't handle nested list, you should use other jquery plug ins that does (giyf).

If you wish to modify html output out of your copied mod_mainmenu, then simply just locate/modify corresponding code (it ought to be inside a view since joomla use mvc).