From 4a5644e51a964bbe9a41f2ad37190641b5595d41 Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 10 Mar 2004 02:19:17 +0000 Subject: [PATCH] New generic function to break up long words --- lib/weblib.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/weblib.php b/lib/weblib.php index f800969eb5..d605d1742e 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -192,6 +192,32 @@ function stripslashes_safe($string) { return $string; } + +function break_up_long_words($string, $maxsize=20, $cutchar=' ') { +/// Given some normal text, this function will break up any +/// long words to a given size, by inserting the given character + + $output = ''; + $length = strlen($string); + $wordlength = 0; + + for ($i=0; $i<$length; $i++) { + $char = $string[$i]; + if ($char == ' ' or $char == "\t" or $char == "\n" or $char == "\r") { + $wordlength = 0; + } else { + $wordlength++; + if ($wordlength > $maxsize) { + $output .= $cutchar; + $wordlength = 0; + } + } + $output .= $char; + } + return $output; +} + + if (!function_exists('str_ireplace')) { /// Only exists in PHP 5 function str_ireplace($find, $replace, $string) { /// This does a search and replace, ignoring case -- 2.39.5