aboutsummaryrefslogtreecommitdiffstats
path: root/include/text.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-06-17 07:33:45 +0000
committerMario <mario@mariovavti.com>2021-06-17 07:33:45 +0000
commitb55676d08914d58927b5503a1bfa283397cd6d44 (patch)
tree34827895f126f9afe0c1db284e089632e19984c6 /include/text.php
parentb5a8ca6ef72366d355c99702f0a775ccc36734d5 (diff)
downloadvolse-hubzilla-b55676d08914d58927b5503a1bfa283397cd6d44.tar.gz
volse-hubzilla-b55676d08914d58927b5503a1bfa283397cd6d44.tar.bz2
volse-hubzilla-b55676d08914d58927b5503a1bfa283397cd6d44.zip
New landing page HQ with separate views for direct messages, public/limited messages and starred messages if the feature is enabled
Diffstat (limited to 'include/text.php')
-rw-r--r--include/text.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/include/text.php b/include/text.php
index 8dc5ee188..a0c2689af 100644
--- a/include/text.php
+++ b/include/text.php
@@ -3880,3 +3880,30 @@ function sanitize_text_field($str) {
return preg_replace('/\s+/S', ' ', $str);
}
+/**
+ * @brief shortens a string to $max_length without cutting off words
+ * @param string $str
+ * @param intval $max_length
+ * @param string $suffix (optional)
+
+ * @return string
+ */
+function substr_words($str, $max_length, $suffix = '...') {
+
+ if (strlen($str) > $max_length) {
+ $words = preg_split('/\s/', $str);
+ $ret = '';
+ $i = 0;
+ while (true) {
+ $length = (strlen($ret) + strlen($words[$i]));
+ if ($length > $max_length) {
+ break;
+ }
+ $ret .= " " . $words[$i];
+ ++$i;
+ }
+ $ret .= $suffix;
+ }
+
+ return (($ret) ? $ret : $str);
+}