Få ut ungefärlig lästid på ett stycke text

/*
 *	Approximation of reading time of an unknown mass of text
 *	
 */
function get_read_time($content) {
	$contentText = $content;
	$no_of_words = str_word_count($contentText);
	$wpm = 200;
	$time = round($no_of_words/$wpm);
	
	if ( $time < 1 ) {
		$time = 'några sekunder';
	} elseif ( $time == 1 ) {
		$time = '~ 1 minut';
	} else {
		$time = '~' . $time . ' minuter';
	}
	
	return $time;
}

Författare: Erik

Erik har jobbat med webb professionellt sedan 2008. Från 2005 till 2008 studerades webb på ING/JTH och dessförinnan skapades webb på all fritid. Första sajten byggdes någon gång mellan 1996-1998.