]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Tools/Utils.php
Counting two characters together as a word in CJK
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tools / Utils.php
CommitLineData
0c83fd59
J
1<?php
2
3namespace Wallabag\CoreBundle\Tools;
4
5class Utils
6{
7 /**
4346a860 8 * Generate a token used for RSS.
0c83fd59 9 *
23afdf3a 10 * @param int $length Length of the token
7a0e6970 11 *
0c83fd59
J
12 * @return string
13 */
7a0e6970 14 public static function generateToken($length = 15)
0c83fd59 15 {
7a0e6970 16 $token = substr(base64_encode(random_bytes($length)), 0, $length);
0c83fd59 17
132f614d 18 // remove character which can broken the url
4094ea47 19 return str_replace(['+', '/'], '', $token);
0c83fd59 20 }
6eebd8c9
JB
21
22 /**
35983eb9 23 * For a given text, we calculate reading time for an article based on 200 words per minute.
6eebd8c9 24 *
35983eb9 25 * @param string $text
6eebd8c9
JB
26 *
27 * @return float
28 */
29 public static function getReadingTime($text)
30 {
7f8630b9 31 return floor(\count(preg_split('~([^\p{L}\p{N}\']+|(\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul}){1,2})~u', strip_tags($text))) / 200);
6eebd8c9 32 }
0c83fd59 33}