Since you asked for “fast”, here is one liner that does the job:
$url = 'HtTp://User:Pass@www.ExAmPle.com:80/Blah';
echo preg_replace_callback(
'#(^[a-z]+://)(.+@)?([^/]+)(.*)$#i',
create_function('$m',
'return strtolower($m[1]).$m[2].strtolower($m[3]).$m[4];'),
$url);
Outputs:
http://User:Pass@www.example.com:80/Blah
EDIT / ADD:
I tested, and this version is about 55% faster than using preg_replace_callback with an anonymous function:
echo preg_replace(
'#(^[a-z]+://)(.+@)?([^/]+)(.*)$#ei',
"strtolower('\\1').'\\2'.strtolower('\\3').'\\4'",
$url);
source
share