0

Example user input

http://domain.com/
hTTp://domain.com/Cars/
hTtp://www.domain.com/pAge/

I want a php function to make the output like

domain.com
domain.com/Cars/
www.domain.com/pAge/

Let me know :)

4 Answers4

5

You don't need regular expressions here, just use parse_url and str_replace:

$url = 'hTtp://www.domain.com/pAge/';
$url = str_replace( parse_url( $url, PHP_URL_SCHEME ) . '://', '', $url );
Danijel
  • 12,408
  • 5
  • 38
  • 54
1

Consider using parse_url() to get an array with the different parts of the url and rebuild it as a string any way you want.

qrazi
  • 1,406
  • 1
  • 15
  • 18
0

Consider using a regex, with preg_replace $converted = preg_replace('#^h+t+p+s+?://#i', '', $stringtoprocess);

Thomas P.
  • 463
  • 4
  • 12
0

Maybe the easiest way might be

echo str_replace('//','',strstr($url, '//'));
baao
  • 71,625
  • 17
  • 143
  • 203