diff options
author | Thomas Lange <code@nerdmind.de> | 2018-09-09 22:58:30 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2018-09-09 23:05:18 +0200 |
commit | 5cf59f6700c4ea73932b68b0afeb0aa5f2a3e9ca (patch) | |
tree | 6912d1abee00d0a79141215a6f6e29adf0998078 /core/functions.php | |
parent | a081cbabaa14e45ae336bd06f0c005580502a525 (diff) | |
download | blog-5cf59f6700c4ea73932b68b0afeb0aa5f2a3e9ca.tar.gz blog-5cf59f6700c4ea73932b68b0afeb0aa5f2a3e9ca.tar.xz blog-5cf59f6700c4ea73932b68b0afeb0aa5f2a3e9ca.zip |
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.
Diffstat (limited to 'core/functions.php')
-rw-r--r-- | core/functions.php | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/core/functions.php b/core/functions.php index 7bddb5b..558acf2 100644 --- a/core/functions.php +++ b/core/functions.php @@ -217,6 +217,20 @@ 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 = " <span title=\"{$explanation}\">{$emoticon}</span>"; + + $string = preg_replace($pattern, $replace, $string); + } + + return $string; +} + +#=============================================================================== # Wrapper function for htmlspecialchars() #=============================================================================== function escapeHTML($string): string { |