From 6c603fdc527d8bad1e7ba45e41880ad7dcb0c327 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 20 Jul 2015 15:46:15 +0100 Subject: [PATCH] Use mbstring in flowdock handler when possible to compute short messages, fixes #567 --- src/Monolog/Formatter/FlowdockFormatter.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Formatter/FlowdockFormatter.php b/src/Monolog/Formatter/FlowdockFormatter.php index af63d011..5094af3c 100644 --- a/src/Monolog/Formatter/FlowdockFormatter.php +++ b/src/Monolog/Formatter/FlowdockFormatter.php @@ -93,10 +93,22 @@ class FlowdockFormatter implements FormatterInterface */ public function getShortMessage($message) { + static $hasMbString; + + if (null === $hasMbString) { + $hasMbString = function_exists('mb_strlen'); + } + $maxLength = 45; - if (strlen($message) > $maxLength) { - $message = substr($message, 0, $maxLength - 4) . ' ...'; + if ($hasMbString) { + if (mb_strlen($message, 'UTF-8') > $maxLength) { + $message = mb_substr($message, 0, $maxLength - 4, 'UTF-8') . ' ...'; + } + } else { + if (strlen($message) > $maxLength) { + $message = substr($message, 0, $maxLength - 4) . ' ...'; + } } return $message;