aboutsummaryrefslogtreecommitdiffstats
path: root/core/functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/functions.php')
-rw-r--r--core/functions.php18
1 files changed, 10 insertions, 8 deletions
diff --git a/core/functions.php b/core/functions.php
index a9d103e..b622601 100644
--- a/core/functions.php
+++ b/core/functions.php
@@ -306,14 +306,16 @@ function getUnicodeEmoticons(): array {
# Wrap emoticons in <span> element with "title" attribute for explanation
#===============================================================================
function parseUnicodeEmoticons($string): string {
- foreach(getUnicodeEmoticons() as $emoticon => $explanation) {
- $pattern = '#(^|\s)'.preg_quote($emoticon).'#';
- $replace = "\\1<span title=\"{$explanation}\">{$emoticon}</span>";
-
- $string = preg_replace($pattern, $replace, $string);
- }
-
- return $string;
+ $emoticon_data = getUnicodeEmoticons();
+ $emoticon_list = array_keys($emoticon_data);
+ $emoticon_list = implode('|', $emoticon_list);
+
+ return preg_replace_callback("#($emoticon_list)#", function($matches)
+ use($emoticon_data) {
+ $emoticon = $matches[1];
+ $explanation = $emoticon_data[$emoticon];
+ return sprintf('<span title="%s">%s</span>', $explanation, $emoticon);
+ }, $string);
}
#===============================================================================