How do I remove http, https and slash from user input in php

Blur picture Blur · Dec 5, 2010 · Viewed 48.3k times · Source

Example user input

http://domain.com/
http://domain.com/topic/
http://domain.com/topic/cars/
http://www.domain.com/topic/questions/

I want a php function to make the output like

domain.com
domain.com/topic/
domain.com/topic/cars/
www.domain.com/topic/questions/

Let me know :)

Answer

user1985367 picture user1985367 · Jan 16, 2013

ereg_replace is now deprecated, so it is better to use:

$url = preg_replace("(^https?://)", "", $url );

This removes either http:// or https://