From 5cf59f6700c4ea73932b68b0afeb0aa5f2a3e9ca Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sun, 9 Sep 2018 22:58:30 +0200 Subject: Add function "parseUnicodeEmoticons" This function wraps all the UTF-8 encoded emoticons (from "getUnicodeEmoticons") found in $string into a "span" element with a "title" attribute, which will contain the emoticon explanation text. --- core/functions.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/functions.php b/core/functions.php index 7bddb5b..558acf2 100644 --- a/core/functions.php +++ b/core/functions.php @@ -216,6 +216,20 @@ function getUnicodeEmoticons(): array { ]; } +#=============================================================================== +# Wrap emoticons in element with "title" attribute for explanation +#=============================================================================== +function parseUnicodeEmoticons($string): string { + foreach(getUnicodeEmoticons() as $emoticon => $explanation) { + $pattern = '#(^|\s)'.preg_quote($emoticon).'#'; + $replace = " {$emoticon}"; + + $string = preg_replace($pattern, $replace, $string); + } + + return $string; +} + #=============================================================================== # Wrapper function for htmlspecialchars() #=============================================================================== -- cgit v1.2.3