/i' => '<script$1>', '/\<\/script\>/i' => '</script>' ]; /** * Script Tag Chars Decode * * @var array */ protected static $scriptTagCharsDecode = [ '/\&\#60\;script(.*?)\&\#62\;/i' => '', '/\&\#60\;\/script\&\#62\;/i' => '' ]; /** * Encode Script Tags * * @param string $str * * @return string */ public static function encode(string $str) : string { return preg_replace ( array_keys(self::$scriptTagChars), array_values(self::$scriptTagChars), $str ); } /** * Decode Script Tags * * @param string $str * * @return string */ public static function decode(string $str) : string { return preg_replace ( array_keys(self::$scriptTagCharsDecode), array_values(self::$scriptTagCharsDecode), $str ); } }