aboutsummaryrefslogtreecommitdiffhomepage
path: root/misc/hostname_from_uri.php
diff options
context:
space:
mode:
authorwinter2024-12-17 18:39:18 +0000
committerwinter2024-12-17 18:39:18 +0000
commit085762ec174eae1c519ec14db632f5ba197ed3c7 (patch)
tree9ad49bc839b5f72ded47c119ff01a09dfa0b934a /misc/hostname_from_uri.php
parentbc2cd99b108b8755a648c3915714e7c0e0771548 (diff)
hopefully implement push!
again i can't really test this yet because i don't have two https instances that can talk to each other. soon i will set that up and test all these recent commits
Diffstat (limited to 'misc/hostname_from_uri.php')
-rw-r--r--misc/hostname_from_uri.php19
1 files changed, 19 insertions, 0 deletions
diff --git a/misc/hostname_from_uri.php b/misc/hostname_from_uri.php
new file mode 100644
index 0000000..0ee6b05
--- /dev/null
+++ b/misc/hostname_from_uri.php
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * Extracts the hostname (and port) from the given URI, assuming it is of a known scheme and can have one
+ * @param string $uri
+ * @return ?string the host:port pair if there is one or null otherwise
+ */
+function hostname_from_uri(string $uri): ?string {
+ if (!(
+ str_starts_with($uri, 'https://') ||
+ str_starts_with($uri, 'http://') ||
+ str_starts_with($uri, 'gopher://') ||
+ str_starts_with($uri, 'gemini://') ||
+ str_starts_with($uri, 'mumble://')
+ )) {
+ return null;
+ }
+ return explode('/', $uri, 4)[2];
+} \ No newline at end of file