From db65cb46c21e9265cb7460525df8907b8f2a9e35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 9 Jun 2021 15:37:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/function.php b/function.php index 78d76386..fbe7c5e2 100644 --- a/function.php +++ b/function.php @@ -375,6 +375,34 @@ if (!function_exists('logger')) { } } + +if (!function_exists('trimAll')) { + + + /** + * @param $content + * @param int $len + * @param string $encode + * @param bool $htmlTags + * @return string|string[]|null + */ + function trimAll($content, $len = 0, $encode = 'utf-8', $htmlTags = true): array|string|null + { + $str = trim($content); + if ($htmlTags) { + $str = strip_tags($str); + } + $str = preg_replace('/[\n|\r|\t]+/', '', $str); + $str = preg_replace("/(\s|\ \;| |\xc2\xa0)/", '', $str); + if ($len > 0) { + return mb_substr($str, 0, $len, $encode); + } else { + return $str; + } + } +} + + if (!function_exists('get_file_extension')) { function get_file_extension($filename)