Search code examples
phparraysstringparse-url

How to store parse_url as a string in PHP?


I have the following code:

$array = parse_url($_SERVER['HTTP_REFERER']);
$Ur = $array['host'];

which displays the domain just fine, but when I use this with sessions, it doesn't work. Also, I tested it with gettype and it returns Null? I thought it was an array?

Anywho, how do I go about converting the above $Ur into a string?

Cheers!


Solution

  • provide a second component parameter = PHP_URL_HOST to parse_url and it will return a string instead of an array