diff options
| author | Jason Lam <3edgy6u@gmail.com> | 2014-05-09 20:42:05 -0400 |
|---|---|---|
| committer | Jason Lam <3edgy6u@gmail.com> | 2014-05-09 20:42:05 -0400 |
| commit | eca5c383e1035d538d2bc81a9802c76929bf053e (patch) | |
| tree | b9749d96a71b1d7c5e0495f6afabba7ef057923b /inc | |
| parent | 9bd0572b63e5a2bc98da0375ab2bd32b546efd12 (diff) | |
added truncate_filename function
Diffstat (limited to 'inc')
| -rw-r--r-- | inc/display.php | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/inc/display.php b/inc/display.php index c836247e..a859fbdb 100644 --- a/inc/display.php +++ b/inc/display.php @@ -253,6 +253,16 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) { return $body; } +function truncate_filename($filename, $length) { + if (strlen($filename) <= $length) return $filename; + $matches = array(); + if (!preg_match("/.*(\\..+)/", $filename, $matches)) return $filename // what, no extension + $length -= strlen($matches[1]); + if ($length <= 0) return '(...)' . $matches[1]; // lmao + $filename = substr($filename, 0, $length) . '(...)' . $matches[1]; + return $filename; +} + function bidi_cleanup($data) { // Closes all embedded RTL and LTR unicode formatting blocks in a string so that // it can be used inside another without controlling its direction. |
