I would like to search and replace some tags with regexp.
this is my starting string:
<p>some bla bla bla</p>
<p class="normale">•bla bla and bla</p><p class="normale">•bla bla and bla</p>
<p class="normale">•bla bla and bla</p><p class="normale">•bla bla and bla</p><p class="normale">•bla bla and bla</p>
<p>other bla bla bla</p>
<p class="normale">•bla bla and bla</p><p class="normale">•bla bla and bla</p>
<p class="normale">•bla bla and bla</p><p class="normale">•bla bla and bla</p>
<p>other bla bla bla</p>
and this is the result that I want
<p>some bla bla bla</p>
<ul><li>bla bla and bla</li><li>bla bla and bla</li>
<li>bla bla and bla</li><li>bla bla and bla</li><li>bla bla and bla</li></ul>
<p>other bla bla bla</p>
<ul><li>bla bla and bla</li><li>bla bla and bla</li>
<li>bla bla and bla</li><li>bla bla and bla</li>
<li>other bla bla bla</li></ul>
So I want to substitute all <p>• or <p>• with <li> and </p> with </li> and regroup every group of <li></li><li></li><li></li> in <ul></ul>
For now I have done some test and the code below is the result, but I don't think is the best way, and the regroup part isn't complete.
Searching and Replace
// base string
$test = '<p>some bla bla bla</p>
  <p class="normale">•bla bla and bla</p><p class="normale">•bla bla and bla</p>
  <p class="normale">•bla bla and bla</p><p class="normale">•bla bla and bla</p><p class="normale">•bla bla and bla</p>
  <p>other bla bla bla</p>
  <p class="normale">•bla bla and bla</p><p class="normale">•bla bla and bla</p>
  <p class="normale">•bla bla and bla</p><p class="normale">•bla bla and bla</p>
  <p>other bla bla bla</p>';
// First replace, I don't know but I can't find any • or • with regexp
$text = str_replace(array('•', '•'), '!SUB!', $text);
$regexp = '/(<p( class="normale"){0,}>(!SUB!))(.*?)<\/p>/';
// replace bulled paragraph with li tags
$text = preg_replace($regexp, "<li>$4</li>\n", $text);
But the part that regroup what I have found is very hard, and I don't know how to proceed
 
     
     
    
` because you replaced it)
– Niet the Dark Absol Apr 17 '12 at 14:13•{some text}
` with `