src/Bookworm/Bookworm.php
public static function estimate($text, $units = array(' minute', ' minutes'))
    {
        // Count how many words are in the given text
        $wordCount = self::countWords($text);
        $wordSeconds = ($wordCount / self::$wordsPerMinute) * 60;
        // Count how many images are in the given text
        $imageCount = self::countImages($text);
        $imageSeconds = $imageCount * self::$secondsPerImage;
        // Count how many images are in the given text
        $codeCount = self::countCode($text);
        $codeSeconds = ($codeCount / self::$codewordsPerMinute) * 60;
        // Calculate the amount of minutes required to read the text
        $minutes = round(($wordSeconds + $imageSeconds + $codeSeconds) / 60);
        // If it's smaller than one or one, we default it to one
        $minutes = $minutes > 1 ? $minutes : 1;

        // return only int, if $units set to false

        if (is_string($units) === true) {
            return $minutes.$units;
        }

        if (is_array($units) === true && count($units) === 2) {
            $units = array_values($units);

            return $minutes.($minutes === 1 ? $units[0] : $units[1]);
        }

        return $minutes;
    }
public static function estimate($text, $units = array(' minute', ' minutes'))
    {
        // Count how many words are in the given text
        $wordCount = self::countWords($text);
        $wordSeconds = ($wordCount / self::$wordsPerMinute) * 60;
        // Count how many images are in the given text
        $imageCount = self::countImages($text);
        $imageSeconds = $imageCount * self::$secondsPerImage;
        // Count how many images are in the given text
        $codeCount = self::countCode($text);
        $codeSeconds = ($codeCount / self::$codewordsPerMinute) * 60;
        // Calculate the amount of minutes required to read the text
        $minutes = round(($wordSeconds + $imageSeconds + $codeSeconds) / 60);
        // If it's smaller than one or one, we default it to one
        $minutes = $minutes > 1 ? $minutes : 1;

        // return only int, if $units set to false

        if (is_string($units) === true) {
            return $minutes.$units;
        }

        if (is_array($units) === true && count($units) === 2) {
            $units = array_values($units);

            return $minutes.($minutes === 1 ? $units[0] : $units[1]);
        }

        return $minutes;
    }
public static function estimate ( $ text , $ units = array ( ' minute' , ' minutes' ) ) { // Count how many words are in the given text $ wordCount = self :: countWords ( $ text ) ; $ wordSeconds = ( $ wordCount / self :: $ wordsPerMinute ) * 60 ; // Count how many images are in the given text $ imageCount = self :: countImages ( $ text ) ; $ imageSeconds = $ imageCount * self :: $ secondsPerImage ; // Count how many images are in the given text $ codeCount = self :: countCode ( $ text ) ; $ codeSeconds = ( $ codeCount / self :: $ codewordsPerMinute ) * 60 ; // Calculate the amount of minutes required to read the text $ minutes = round ( ( $ wordSeconds + $ imageSeconds + $ codeSeconds ) / 60 ) ; // If it's smaller than one or one, we default it to one $ minutes = $ minutes > 1 ? $ minutes : 1 ; // return only int, if $units set to false if ( is_string ( $ units ) === true ) { return $ minutes . $ units ; } if ( is_array ( $ units ) === true && count ( $ units ) === 2 ) { $ units = array_values ( $ units ) ; return $ minutes . ( $ minutes === 1 ? $ units [ 0 ] : $ units [ 1 ] ) ; } return $ minutes ; }
Estimates the time needed to read a given string.

@param string       $text  The text to estimate
@param string|array $units singular | singular & plural

@return string
Estimates the time needed to read a given string .