Wow. I came here from google expecting to find a one liner to copy and paste!
You don't need a function to do this because one already exists. Just do:
echo explode("//", "https://anyurl.any.tld/any/directory/structure", 2)[1];
In this example, explode() will return an array of:
["https:", "anyurl.any.tld/any/directory/structure"]
And we want the 2nd element. This will handle http, https, ftp, or pretty much any URI, without needing regex.
https://www.php.net/manual/en/function.explode.php
If you want a function:
function removeProtocols($uri) { return explode("//", $uri, 2)[1]; }
EDIT: See user comment from Harry Lewis... this is my favourite way to do this now.