Example user input
http://domain.com/
http://domain.com/topic/
http://domain.com/topic/cars/
http://www.domain.com/topic/questions/
I want
Create an array:
$remove = array("http://","https://");
and replace with empty string:
str_replace($remove,"",$url);
it would look something like this:
function removeProtocol($url){
$remove = array("http://","https://");
return str_replace($remove,"",$url);
}
Str_replace will return a string if your haystack (input) is a string and you replace your needle(s) in the array with a string. It's nice so you can avoid all the extra looping.
Happy Coding!