+
+
+ /**
+ * Check if the trimmed provided string is starting with one of the provided characters
+ *
+ * @param string $string
+ * @param array $chars
+ * @return bool
+ */
+ public static function startsWith($string, array $chars)
+ {
+ $return = in_array(substr(trim($string), 0, 1), $chars);
+
+ return $return;
+ }
+
+ /**
+ * Returns the regular expression string to match URLs in a given text
+ *
+ * @return string
+ * @see https://daringfireball.net/2010/07/improved_regex_for_matching_urls
+ */
+ public static function autoLinkRegEx()
+ {
+ return '@
+(?<![=\'\]"/]) # Not preceded by [, =, \', ], ", /
+\b
+( # Capture 1: entire matched URL
+ https?:// # http or https protocol
+ (?:
+ [^/\s\xA0`!()\[\]{};:\'",<>?«»“”‘’.] # Domain can\'t start with a .
+ [^/\s\xA0`!()\[\]{};:\'",<>?«»“”‘’]+ # Domain can\'t end with a .
+ \.
+ [^/\s\xA0`!()\[\]{};:\'".,<>?«»“”‘’]+/? # Followed by a slash
+ )
+ (?: # One or more:
+ [^\s\xA0()<>]+ # Run of non-space, non-()<>
+ | # or
+ \(([^\s\xA0()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
+ | # or
+ [^\s\xA0`!()\[\]{};:\'".,<>?«»“”‘’] # not a space or one of these punct chars
+ )*
+)@xiu';
+ }
+
+ /**
+ * Ensures a single path item doesn't contain any path-traversing characters
+ *
+ * @see https://stackoverflow.com/a/46097713
+ * @param string $pathItem
+ * @return string
+ */
+ public static function sanitizeFilePathItem($pathItem)
+ {
+ $pathItem = str_replace('/', '_', $pathItem);
+ $pathItem = str_replace('\\', '_', $pathItem);
+ $pathItem = str_replace(DIRECTORY_SEPARATOR, '_', $pathItem); // In case it does not equal the standard values
+
+ return $pathItem;
+ }