title: remove all attributes in php but keep href, terget, rel in link as is
body: <p>Please suggest me the <strong>PHP regex</strong> for <strong>preg_replace</strong> to remove all the attributes from tags in HTML code without removing the tags. But in hyper links all the attributes such as href, terget, rel should remain as is</p>
  
  <p>Please refer the below example:</p>
  
  <p>I already tried below <strong>regex</strong> with <strong>preg_replace</strong>:</p>
  
  <pre><code>$htmltext = '&lt;p style="float: left;"&gt;
  &lt;span style="color: #ff0000;"&gt;
  &lt;b&gt;Some text here&lt;/b&gt;
  &lt;/span&gt;
  &lt;a target="_blank" rel="nofollow" href="http://thebankexam.com/page/7017"&gt;Clickable Text&lt;/a&gt;
  &lt;/p&gt;';
  $my_output = preg_replace("/&lt;([a-z][a-z0-9]*)[^&gt;]*?(\/?)&gt;/i",'&lt;$1$2&gt;',$htmltext);
  echo $my_output;
  </code></pre>
  
  <p><strong>Filtered output ($my_output):</strong></p>
  
  <pre><code>&lt;p&gt;
  &lt;span&gt;
  &lt;b&gt;Some text here&lt;/b&gt;
  &lt;/span&gt;
  &lt;a&gt;Clickable Text&lt;/a&gt;  &lt;!-- Check this hyper link href, rel and target gone --&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p><strong>The intended output should look like:</strong></p>
  
  <pre><code>&lt;p&gt;
  &lt;span&gt;
  &lt;b&gt;Some text here&lt;/b&gt;
  &lt;/span&gt;
  &lt;a target="_blank" rel="nofollow" href="http://thebankexam.com/page/7017"&gt;Clickable Text&lt;/a&gt;
  &lt;/p&gt;
  </code></pre>