Skip to content

Commit

Permalink
Fix undefined utf8_decode() error
Browse files Browse the repository at this point in the history
  • Loading branch information
kksidd committed May 1, 2019
1 parent 0b138dc commit 6ffd20e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion couch/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 6ffd20e

Please sign in to comment.