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);
  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 = $doc->saveHTML();
  13.  
  14. echo $string;
Success #stdin #stdout 0.02s 24752KB
stdin
Standard input is empty
stdout
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://w...content-available-to-author-only...3.org/TR/REC-html40/loose.dtd">
<html><body><p>Texto de teste  Teste Lorem Ipsim </p></body></html>