From 7856c7ea0ed134c4dfee5c9ae2b4e7e2f9ab8b79 Mon Sep 17 00:00:00 2001 From: jwangen Date: Sat, 5 Oct 2002 00:07:19 +0000 Subject: Minor changes, implemented use configable number of lines for line wrappings --- functions/draw_functions.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'functions/draw_functions.php') diff --git a/functions/draw_functions.php b/functions/draw_functions.php index 52f6d47..d54c250 100644 --- a/functions/draw_functions.php +++ b/functions/draw_functions.php @@ -34,4 +34,27 @@ function drawEventTimes ($start, $end) { return array ("draw_start" => ($sta_h . $sta_min), "draw_end" => ($end_h . $end_min), "draw_length" => $draw_len); } + +// word wrap function that returns specified number of lines +// when lines is 0, it returns the entire string as wordwrap() does it +function word_wrap($str, $length, $lines=0) { + $str = wordwrap($str, $length); + if ($lines > 0) { + $str_arr = explode("\n", $str); + if (count($str_arr) < $lines) $lines = count($str_arr); + $str = ''; + for ($i=0; $i<($lines-1);$i++) { + $str .= $str_arr[$i].'
'; + } + if (count($str_arr) > ($lines)) { + $tmp_str = substr($str_arr[$i], 0, ($length-2)); + $str .= $tmp_str . '...'; + } else { + $str .= $str_arr[$i]; + } + } else { + $str = nl2br(trim($str)); + } + return $str; +} ?> \ No newline at end of file -- cgit v1.2.3