From 87e35716c1997f76e6ea6e64aab9357bf71fc149 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Mon, 28 Mar 2022 03:17:01 +0100 Subject: [PATCH] [UTIL] Add Formatting::explode(array , string ) --- src/Util/Formatting.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Util/Formatting.php b/src/Util/Formatting.php index 54f5068f19..94d5ad02c7 100644 --- a/src/Util/Formatting.php +++ b/src/Util/Formatting.php @@ -235,6 +235,19 @@ abstract class Formatting return false; } + /** + * Like \explode, but with multiple options for the delimiter. Will use the first one present + */ + public static function explode(array $separators, string $string) + { + foreach ($separators as $sep) { + if (str_contains($string, $sep)) { + return explode($sep, $string); + } + } + return $string; + } + /** * Render a plain text note content into HTML, extracting links and tags */