Contao\StringUtil::censor PHP Метод

censor() публичный статический Метод

Censor a single word or an array of words within a string
public static censor ( string $strString, mixed $varWords, string $strReplace = '' ) : string
$strString string The string to censor
$varWords mixed A string or array or words to replace
$strReplace string An optional replacement string
Результат string The cleaned string
    public static function censor($strString, $varWords, $strReplace = '')
    {
        foreach ((array) $varWords as $strWord) {
            $strString = preg_replace('/\\b(' . str_replace('\\*', '\\w*?', preg_quote($strWord, '/')) . ')\\b/i', $strReplace, $strString);
        }
        return $strString;
    }

Usage Example

 /**
  * Censor a single word or an array of words within a string.
  *
  * @param string $strString  The string to censor.
  *
  * @param mixed  $varWords   A string or array or words to replace.
  *
  * @param string $strReplace An optional replacement string.
  *
  * @return string The cleaned string
  */
 public static function censor($strString, $varWords, $strReplace = '')
 {
     if (self::isStringUtilAvailable()) {
         return StringUtil::censor($strString, $varWords, $strReplace);
     }
     return \Contao\String::censor($strString, $varWords, $strReplace);
 }