X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FStrings.php;h=fff218e46602ee63e8a9d202297df3c7df30396a;hb=3bca4fe2a64671d09e08346456cdfa6c12f996e9;hp=c5d5c760a382872631bd84ece791da33a223bed7;hpb=4db4d1843d19a810f3039558d312f0de030e7d6e;p=friendica.git diff --git a/src/Util/Strings.php b/src/Util/Strings.php index c5d5c760a3..fff218e466 100644 --- a/src/Util/Strings.php +++ b/src/Util/Strings.php @@ -1,6 +1,6 @@ $text, 'regex' => $regex, 'blocks' => $blocks, 'executionId' => $executionId, 'callstack' => System::callstack(10)]); + Logger::notice('Received null value from preg_replace_callback', ['text' => $text, 'regex' => $regex, 'blocks' => $blocks, 'executionId' => $executionId]); } $text = $callback($return ?? $text) ?? ''; @@ -532,7 +531,7 @@ class Strings } /** - * This function converts a PHP's shorhand notation string for file sizes in to an integer number of total bytes. + * This function converts a file size string written in PHP's shorthand notation to an integer number of total bytes. * For example: The string for shorthand notation of '2M' (which is 2,097,152 Bytes) is converted to 2097152 * @see https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes * @param string $shorthand @@ -561,4 +560,22 @@ class Strings return $shorthand; } + /** + * Converts an URL in a nicer format (without the scheme and possibly shortened) + * + * @param string $url URL that is about to be reformatted + * @return string reformatted link + */ + public static function getStyledURL(string $url): string + { + $parts = parse_url($url); + $scheme = [$parts['scheme'] . '://www.', $parts['scheme'] . '://']; + $styled_url = str_replace($scheme, '', $url); + + if (strlen($styled_url) > 30) { + $styled_url = substr($styled_url, 0, 30) . "…"; + } + + return $styled_url; + } }