From 6ffd20e2e2c1a17961c683e54fcd85233b053e55 Mon Sep 17 00:00:00 2001 From: kksidd Date: Wed, 1 May 2019 16:19:41 +0530 Subject: [PATCH] Fix undefined utf8_decode() error --- couch/functions.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/couch/functions.php b/couch/functions.php index d327517..3646edd 100644 --- a/couch/functions.php +++ b/couch/functions.php @@ -900,7 +900,22 @@ function excerpt( $str_utf, $count, $trail='' ){ } } else{ - $strlen = strlen( utf8_decode($str_utf) ); + if( function_exists('utf8_decode') ){ + $strlen = strlen( utf8_decode($str_utf) ); + } + else{ + // adapted from Symfony Polyfill (https://github.com/symfony/polyfill) + $ulen_mask = array( "\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4 ); + $i = $j = 0; + $len = strlen( $str_utf ); + while( $i < $len ){ + $u = $str_utf[$i] & "\xF0"; + $i += isset($ulen_mask[$u]) ? $ulen_mask[$u] : 1; + ++$j; + } + $strlen = $j; + } + if( $count < $strlen ){ $pattern = '#^(.{'.$count.'})#us'; @preg_match( $pattern, $str_utf, $matches );