fork download
  1. <?php
  2.  
  3. $string = 'Texto de teste <i class="fab fa-accusoft">xxx</i> Teste Lorem Ipsim <i class="fab fa-accusoft">xxx</i>';
  4. $doc = new DOMDocument();
  5. $doc->loadHTML($string, LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD);
  6.  
  7. $selector = new DOMXPath($doc);
  8. foreach($selector->query('//i[contains(attribute::class, "fa-")]') as $e){
  9. $e->parentNode->removeChild($e);
  10. }
  11.  
  12. $string = trim(preg_replace('/<p>|<\/p>/', '', str_replace(' ', ' ', $doc->saveHTML())));
  13.  
  14. echo $string;
Success #stdin #stdout 0.02s 24912KB
stdin
Standard input is empty
stdout
Texto de teste Teste Lorem Ipsim