Need Help with Manipulating string with HTML List

Hello,
Please look at the strings below. I need a way to convert $string1 to $string2. The <ul> tags need to be removed and then convert the first <li></li> tags to <div> tags. Then all the subsequent <li> tags need to be replaced with <p> tags. Can anyone help me solve this problem?

Thanks



$string1 = '
<ul>
    <li><strong>The John Marshall Law School</strong>, Chicago, Illinois
    Patent and Copyright Protection</li>
    
    <li><strong>IIT Chicago-Kent College Of Law</strong>, Chicago, Illinois</li>
    
    <li>Antehabeo, pagus tristique conventio, nunc iaceo iustum.</li>    
</ul>
';


$string2 = '
<div><strong>The John Marshall Law School</strong>, Chicago, Illinois
Patent and Copyright Protection</div>

<p><strong>IIT Chicago-Kent College Of Law</strong>, Chicago, Illinois</p>

<p>Antehabeo, pagus tristique conventio, nunc iaceo iustum.</p>    
';


Hopefully you have solved the issues

Try this:


$string1 = '
<ul>
    <li><strong>The John Marshall Law School</strong>, Chicago, Illinois 
    Patent and Copyright Protection</li>
    
    <li><strong>IIT Chicago-Kent College Of Law</strong>, Chicago, Illinois</li>
    
    <li>Antehabeo, pagus tristique conventio, nunc iaceo iustum.</li>    
</ul>
';
preg_match_all('/<li>(.*?)<\\/li>?/sm', $string1, $matches);
$i = 0;
$output = '';
foreach($matches[1] as $match){
    $output .= ($i == 0) ? "<div>$match</div>" : "<p>$match</p>";
    $i++;
}
echo $output;

Raju, That works! Thank you very much! I need to learn regular expressions.