File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 44
55class StringProcessor
66{
7+ /**
8+ * Checks whether the current User Agent is a GUI web browser known by a common string, e.g. Firefox.
9+ *
10+ * @param string $user_agent User Agent to check, or null to check HTTP_USER_AGENT environment variable.
11+ * @return boolean Whether the client is using a GUI web browser or not.
12+ */
13+ public static function isBrowser (?string $ user_agent = null ): bool
14+ {
15+ return (1 === \preg_match (
16+ '#(?:AppleWebKit|Chrome|Edge|Firefox|Mozilla|MSIE|Opera|Safari|Trident|WebKit)#i ' ,
17+ $ user_agent ?? \getenv ('HTTP_USER_AGENT ' ) ?? ''
18+ ));
19+ }
20+
721 public static function sanitizeForUrl (array |string $ haystack , bool $ lowercase = true ): array |string
822 {
923 $ result = \preg_replace ('/[^\da-z]+/im ' , '- ' , $ haystack );
You can’t perform that action at this time.
0 commit comments