A shorter and fully compatible solution to UTF-8 and ISO-8859-1 descriptions/titles.
This only allows BR tags, and removes all other HTML allowing line breaks in descriptions which preserves the text presentation.
Removed:
pulling swear words from database. Unnecessary overhead when we can just read a local array.
This only allows BR tags, and removes all other HTML allowing line breaks in descriptions which preserves the text presentation.
Removed:
pulling swear words from database. Unnecessary overhead when we can just read a local array.
function format_comment(string $text): mixed
{
$censor = array('ass', 'shit');
if (strlen($text) > 0) {
$text = str_ireplace($censor, '(censored)', $text);
$text = mb_convert_encoding($text, 'UTF-8', 'ISO-8859-1');
$string = preg_replace('/\r\n|\r|\n/', '<br>', strtr($text, array_combine(array('', '', '', '', '', '', '[img]', '[/img]', '[img=', '[/img]'), array('<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '<img src=', ' />', '<img src=', ' />'))), -1, $count);
if ($count === 0) {
$string = strip_tags($string, '<br>');
}
$smilies = array(':)' => 'smile.png', ':(' => 'sad.png', ';)' => 'wink.png', ':P' => 'razz.png', ':D' => 'grin.png', ':|' => 'plain.png', ':O' => 'suprise.png', ':?' => 'confused.png', '8)' => 'glasses.png', '8o' => 'eek.png', 'B)' => 'cool.png', ':-)' => 'smile-big.png', ':-(' => 'crying.png', ':-*' => 'kiss.png', 'O:-D' => 'angel.png', ':-@' => 'devilish.png', ':o)' => 'monkey.png', ':help' => 'help.png', ':love' => 'love.png', ':warn' => 'warn.png', ':bomb' => 'bomb.png', ':idea' => 'idea.png', ':bad' => 'bad.png', ':!' => 'important.png', 'brb' => 'brb.png');
foreach ($smilies as $code => &$url) {
$string = str_replace($code, '<img style="width:25px;height:25px;vertical-align:middle" src="/images/smilies/' . $url . '" alt="' . $code . '" title="' . $code . '" />', $string);
}
return $string;
}
return false;
}
Last edited by STorrents2020 on 2023-01-21 03:10:17