From 78b585135fc16c268a9de69a1156231873995a49 Mon Sep 17 00:00:00 2001 From: Jason Oster Date: Wed, 20 May 2009 17:10:09 +0000 Subject: Force makeTitle() to limit the amount of text put into a title --- functions/init/sanitize.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'functions/init/sanitize.php') diff --git a/functions/init/sanitize.php b/functions/init/sanitize.php index 5e9d57e..0370f9f 100644 --- a/functions/init/sanitize.php +++ b/functions/init/sanitize.php @@ -33,6 +33,23 @@ function recursiveSanitize($value) { } +/** + * Truncate a string to a specific number of words + */ +function chopToWordCount($string, $count) { + $wc = str_word_count($string); + if ($wc > $count) { + $words = str_word_count($string, 2); + $last_word = array_slice($words, $count, 1, true); + $pos = key($last_word); + $string = substr($string, 0, $pos); + } + return $string; +} + +/** + * Strip "dangerous" HTML to make it safe to print to web browsers + */ function sanitizeForWeb($string) { $string = preg_replace('//', "\n", $string); -- cgit v1.2.3