title: Remove all html tags from a string keeping only one of them. Advanced strip_tags with one identifier attribute
body: <p>I need to remove HTML tags in one string and keep only one type of them. I have one string that contains this:</p>
  
  
  
  <pre class="lang-none prettyprint-override"><code> &lt;!-- comment --&gt;   &lt;div id="55"&gt; text &lt;/div&gt; &lt;span name=annotation value=125&gt; 2 text &lt;/span&gt; &lt;p id="55"&gt; text 3&lt;/p&gt;&lt;span&gt;text 4 &lt;span&gt;
  </code></pre>
  
  <p>and I need this: </p>
  
  <pre class="lang-none prettyprint-override"><code>text  &lt;span name=annotation value=125&gt; 2 text &lt;/span&gt; text 3text4
  </code></pre>
  
  <p>so I need to delete all the HTML tags except those that have this form</p>
  
  <pre class="lang-none prettyprint-override"><code>"/(&lt;span[^&gt;]*annotation[^&gt;]*value=.?(\w*).?[^&gt;]*&gt;)(.*?)&lt;\/span&gt;/"
  </code></pre>
  
  <p>I use this as part of another expression but to get an idea</p>
  
  <p>How can I do this?</p>
  
  <p>I know it can be done with <code>preg_replace()</code>, but I do not know what is the pattern I need. </p>
  
  <p>An example:</p>
  
  <pre class="lang-none prettyprint-override"><code>$str='&lt;!-- comment --&gt;&lt;p&gt;&lt;b&gt;Deoxyribonucleic acid&lt;/b&gt; (&lt;b&gt;DNA&lt;/b&gt;) is 
     a molecule encoding the &lt;a href="/wiki/Genetics" title="Genetics"&gt;genetic&lt;/a&gt; instructions
     used in the development and functioning of all known living &lt;a href="/wiki/Organism" title="Organism"&gt;organi
     sms&lt;/a&gt; and many &lt;a href="/wiki/Virus" title="Virus"&gt;viruses&lt;/a&gt;. Along with &lt;a href="/wiki/RNA" title="RNA"&gt;RNA&lt;/a&gt; and &lt;a href="/wiki/Proteins" title="Proteins" class="mw-redirect"&gt;proteins&lt;/a&gt;, DNA is one of the three major 
     &lt;a href="/wiki/Macromolecules" title="Macromolecules" class="mw-redirect"&gt;macromolecules&lt;/a&gt; 
     that are essential for all known forms of &lt;a href="/wiki/Life" title="Life"&gt;life&lt;/a&gt;.
     Genetic information is encoded&lt;span id="200120131815150" 
     class="mymetastasis" value="247" name="annotation"&gt; as a sequence of nucleotides (&lt;/span&gt;&lt;a href="/wiki/Guanine" title="Guanine"&gt;&lt;span id="200120131815151" class="mymetastasis" value="247" name="annotation"&gt;
     guanine&lt;/span&gt;&lt;/a&gt;&lt;span id="200120131815152" class="mymetastasis" value="247" name="annotation"&gt;, &lt;/span&gt;&lt;a href="/wiki/Adenine" title="Adenine"&gt;&lt;span id="200120131815153" class="mymetastasis" value="247"
     name="annotation"&gt;adenine&lt;/span&gt;&lt;/a&gt;&lt;span id="200120131815154" class="mymetastasis" value="247" name="annotation"&gt;,
     &lt;/span&gt;&lt;a href="/wiki/Thymine" title="Thymine"&gt;&lt;span id="200120131815155" class="mymetastasis" value="247"
     name="annotation"&gt;thymine&lt;/span&gt;&lt;/a&gt;&lt;span id="200120131815156" class="mymetastasis" value="247" name="annotation"&gt;, 
     and &lt;/span&gt;&lt;a href="/wiki/Cytosine" title="Cytosine"&gt;
     &lt;span id="200120131815157" class="mymetastasis" value="247" name="annotation"&gt;cytosine&lt;/span&gt;&lt;/a&gt;&lt;span id="200120131815158" class="mymetastasis" value="247" name="annotation"&gt;) 
     recorded using the letters G, A, T, and C. Most DNA molecules are double-strande&lt;/span&gt;d helices, consisting of two long &lt;a href="/wiki/Polymers" title="Polymers" class="mw-redirect"&gt;polymers&lt;/a&gt; of simple units called &lt;a href="/wiki/Nucleotide" 
     title="Nucleotide"&gt;nucleotides&lt;/a&gt;, molecules with &lt;a href="/wiki/Backbone_chain" title="Backbone chain"&gt;backbones&lt;/a&gt;
     made of alternating &lt;a href="/wiki/Monosaccharide" title="Monosaccharide"&gt;sugars&lt;
     /a&gt; (&lt;a href="/wiki/Deoxyribose" title="Deoxyribose"&gt;deoxyribose&lt;/a&gt;) and &lt;a href="/wiki/Phosphate"
     title="Phosphate"&gt;phosphate&lt;/a&gt; groups (related to phosphoric acid), with the &lt;a href="/wiki/Nucleobases" title="Nucleobases" class="mw-redirect"&gt;nucleobases&lt;/a&gt; (G, A, T, C) attached to the sugars. DNA is well-suited for biological information storage, since the DNA backbone is resistant to cleavage and the double-stranded structure provides the molecule with a 
     built-in duplicate of the encoded information.&lt;/p&gt;';
  </code></pre>
  
  <p>PD:line breaks,tabs,etc are unintentional. Part of the source text.</p>