]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Tools/Utils.php
fix incorrect reading time calculation for entries with CJK characters
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tools / Utils.php
index 71cbc490dd48119a218b1b829f6be4be9c08da57..0a805210872f812b3074595488436234f24e5e13 100644 (file)
@@ -7,7 +7,7 @@ class Utils
     /**
      * Generate a token used for RSS.
      *
-     * @param integer $length Length of the token
+     * @param int $length Length of the token
      *
      * @return string
      */
@@ -16,7 +16,7 @@ class Utils
         $token = substr(base64_encode(random_bytes($length)), 0, $length);
 
         // remove character which can broken the url
-        return str_replace(array('+', '/'), '', $token);
+        return str_replace(['+', '/'], '', $token);
     }
 
     /**
@@ -29,6 +29,6 @@ class Utils
      */
     public static function getReadingTime($text)
     {
-        return floor(str_word_count(strip_tags($text)) / 200);
+        return floor(\count(preg_split('~([^\p{L}\p{N}\']+|\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul})~u', strip_tags($text))) / 200);
     }
 }