fork download
  1. <?php
  2. //Array filled with data from external file
  3. $patterns = array('!test!', 'stuff1', 'all!!', '');
  4.  
  5. //Delete empty values in array
  6. $patterns = array_filter($patterns);
  7.  
  8. foreach($patterns as &$item){
  9. $item = preg_quote($item);
  10. }
  11.  
  12. $pattern = '/(?:-[- ]?| +)(?:'.implode('|', $patterns).')(?:-[- ]?|(?= )|$)/i';
  13.  
  14.  
  15. $clid = "I am the !test! stuff1 all!! string and !test!! not matched";
  16. $clid = trim(preg_replace($pattern, '', $clid));
  17.  
  18. echo $clid;
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
I am the string and !test!! not matched