$value) { $placeholder = $delimiters[0] . $name . $delimiters[1]; if (empty($value)) { $string = preg_replace('/\[[^\[]*' . preg_quote($placeholder) . '[^\]]*\]/', '', $string); } } foreach ($placeholders as $name => $value) { $placeholder = $delimiters[0] . $name . $delimiters[1]; // remove optional marks for nonempty placeholder, e.g: "[{prefix}Title: {title}]" to "{prefix}Title: {title}" if (!empty($value)) { $string = preg_replace('/(\[)([^\[]*' . preg_quote($placeholder) . '[^\]]*)(\])/', '$2', $string); } $string = str_replace($placeholder, $value, $string); } return $string; } public static function toHex($string) { $hex = unpack('H*', $string); return array_shift($hex); } public static function truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) { require_once 'lib/Smarty/Smarty/plugins/modifier.truncate.php'; return smarty_modifier_truncate($string, $length, $etc, $break_words, $middle); } public static function strip_tags($string) { $string = strip_tags($string); $string = str_replace( [ ' ', ' ', '<', '<', '>', '>', '&', '&', '"', '"', ''', ''', '¢', '¢', '£', '£', '¥', '¥', '€', '€', '©', '©', '®', '®', ], [ ' ', ' ', '<', '<', '>', '>', '&', '&', '"', '"', '\'', '\'', '¢', '¢', '£', '£', '¥', '¥', '€', '€', '©', '©', '®', '®', ], $string ); return $string; } }