From 1f3c3cff81972b26fa75d453769ebb726bc931ba Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 20 Jan 2017 11:28:09 +0100 Subject: [PATCH] Fixes #4: support multibytes string split Requires php extension mbstring: --- README.md | 1 + shaarli2twitter/shaarli2twitter.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 834bb69..c20ed0a 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ to post it on Twitter. - PHP 5.3 - PHP cURL extension + - PHP mbstring extension - Shaarli >= v0.8.1 ## Installation diff --git a/shaarli2twitter/shaarli2twitter.php b/shaarli2twitter/shaarli2twitter.php index beedf37..b527285 100644 --- a/shaarli2twitter/shaarli2twitter.php +++ b/shaarli2twitter/shaarli2twitter.php @@ -206,7 +206,7 @@ function replace_placeholder($tweet, $placeholder, $value) // Tweets URL have a fixed size due to t.co $valueLength = ($placeholder != 'url' && $placeholder != 'permalink') ? strlen($value) : TWEET_URL_LENGTH; if ($current + $valueLength > TWEET_LENGTH) { - $value = substr($value, 0, TWEET_LENGTH - $current - 3) . '…'; + $value = mb_strcut($value, 0, TWEET_LENGTH - $current - 3) . '…'; } return str_replace('${'. $placeholder .'}', $value, $tweet); }