Вот полный скрипт для выполнения этой работы. Это в чистом php.
<?php
$dataStr = '<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>';
$tempStr = str_replace('<ul ','<div ',$dataStr);
$dataStr = str_replace('<li class="parent','<h3 class="parent ',$tempStr);
$tempStr = str_replace('<ul>','<div>',$dataStr);
$dataStr = str_replace('</ul>','</div>',$tempStr);
$tempStr = str_replace('</li>','',$dataStr);
$dataStr = str_replace('><a ','><a_keep ',$tempStr);
$tempStr = str_replace('<a ','',$dataStr);
$dataStr = str_replace('<li ','<a ',$tempStr);
$tempStr = str_replace('><a_keep ','><a ',$dataStr);
$dataStr = $tempStr;
$newDataStr = "";
$startIndex = 0;
$endIndex = strpos($dataStr, "\n", $startIndex);
$trimNextLine = false;
while (1==1){
if($endIndex == false){
break;
}
$currentLine = substr($dataStr,$startIndex,$endIndex-$startIndex);
$trimCurrentLine = ltrim($currentLine);
$subStrCurrentLine = substr($trimCurrentLine,0,5);
if($subStrCurrentLine==""){
;//do nothing
}
else if($subStrCurrentLine=="<h3 c"){
$tempString = ' '.ltrim(substr($currentLine,0,strlen($currentLine)));
$newDataStr = $newDataStr . $tempString . "</h3>\n";
}
else if($subStrCurrentLine=="<a cl"){
$tempString = ' '.ltrim(substr($currentLine,0,strlen($currentLine)-1));
$newDataStr = $newDataStr . $tempString;
$trimNextLine = true;
}
else if($subStrCurrentLine=="<div>"){
$tempString = ' '.ltrim(substr($currentLine,0,strlen($currentLine)));
$newDataStr = $newDataStr . $tempString."\n";
$trimNextLine = true;
}
else if($subStrCurrentLine=="</div"){
$tempString = ' '.ltrim(substr($currentLine,0,strlen($currentLine)));
$newDataStr = $newDataStr . $tempString."\n";
$trimNextLine = true;
}
else{
if ($trimNextLine == true){
$trimNextLine = false;
$nextStartIndex = $endIndex+1;
$nextEndIndex = strpos($dataStr, "\n", $nextStartIndex);
$nextLine = substr($dataStr,$nextStartIndex,$nextEndIndex-$nextStartIndex);
$trimNextLine = ltrim($nextLine);
$subStrNextLine = substr($trimNextLine,0,5);
if($subStrNextLine=="<a cl"){
$newDataStr = $newDataStr . ' ' . ltrim($currentLine)."<br />\n";
}
else{
$newDataStr = $newDataStr . ' ' . ltrim($currentLine)."\n";
}
}
else{
$newDataStr = $newDataStr . $currentLine."\n";
}
}
$startIndex = $endIndex+1;
$endIndex = strpos($dataStr, "\n", $startIndex);
}
$tempString = substr($dataStr,$startIndex,strlen($dataStr)-$startIndex);
$newDataStr = $newDataStr . $tempString . "\n";
echo($newDataStr);
?>