Why is parse_url() returning empty string in this case?
$url = "www.example.com";
$host = parse_url($url, PHP_URL_HOST);
print_r($host);
The string is interpreted as relative URL:
// print_r(parse_url('www.vtechpcsupport.com'))
Array
(
[path] => www.vtechpcsupport.com
)
parse_url documentation states: "This function doesn't work with relative URLs." Looks like this isn't "seriously malformed URL" ;)www.vtechpcsupport.com?foo=bar it correctly identifiers foo=bar as query string.This is due to fact that www.vtechpcsupport.com isn't really a URL since it missing the scheme part (HTTP or so), try it like this:
$url = 'http://www.vtechpcsupport.com';
$var = parse_url($url,PHP_URL_HOST);
print($var);
This is because www.vtechpcsupport.com is not a complete URL.
You are specifying PHP_URL_HOST so the function tries to extract just the host part of the URL, which doesn't exist as without a protocol being given the URL is treated as being relative -- so what you want to be the host name is interpreted as a (relative) path.
Try using:
$url='http://www.vtechpcsupport.com';
and you should get the behaviour you expect.