3 * @file src/Content/Text/Plaintext.php
5 namespace Friendica\Content\Text;
16 * @todo For Twitter URLs aren't shortened, but they have to be calculated as if.
18 public static function shorten($msg, $limit)
20 $lines = explode("\n", $msg);
22 $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
23 $ellipsis = html_entity_decode("…", ENT_QUOTES, 'UTF-8');
24 foreach ($lines as $row => $line) {
25 if (iconv_strlen(trim($msg . "\n" . $line), "UTF-8") <= $limit) {
26 $msg = trim($msg . "\n" . $line);
27 } elseif (($msg == "") || (($row == 1) && (substr($msg, 0, 4) == $recycle))) {
28 // Is the new message empty by now or is it a reshared message?
29 $msg = iconv_substr(iconv_substr(trim($msg . "\n" . $line), 0, $limit, "UTF-8"), 0, -3, "UTF-8") . $ellipsis;
39 * Returns the character positions of the provided boundaries, optionally skipping a number of first occurrences
41 * @param string $text Text to search
42 * @param string $open Left boundary
43 * @param string $close Right boundary
44 * @param int $occurrences Number of first occurrences to skip
45 * @return boolean|array
47 public static function getBoundariesPosition($text, $open, $close, $occurrences = 0)
49 if ($occurrences < 0) {
54 for ($i = 0; $i <= $occurrences; $i++) {
55 if ($start_pos !== false) {
56 $start_pos = strpos($text, $open, $start_pos + 1);
60 if ($start_pos === false) {
64 $end_pos = strpos($text, $close, $start_pos);
66 if ($end_pos === false) {
70 $res = ['start' => $start_pos, 'end' => $end_pos];