I want to take var1 and var2 out of the query string and write it (echo) into the HTML.
Seems simple, but my URL needs to be formed like this:
http://example.com/filename.html#var1=FOO&var2=BAR
Notice the hash after the filename -- URL does not contain normal ?
query string delimiter.
How do I accomplish this with a simple function? ... seems like a basic question, but I can't get it to work with URL syntax that requires # before ?.
thanks in advance!
UPDATE UPDATE UDATE - building on the code example in @Musa's answer.
I want to grab the PHP_URL_FRAGMENTS from the window location, and write them into the HTML, I am attempting this:
// get the URL from window location:
$pageURL = $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
$pageURL .= $_SERVER['SERVER_PORT'] != '80' ? $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"] : $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
return $pageURL;
// parse URL including #fragments:
parse_str (parse_url ($pageURL, PHP_URL_FRAGMENT ), $args);
// write var values into the HTML:
echo $args['var1'], ' ', $args['var2'];
I'm either not creating $pageURL
properly, or I'm doing something wrong in the parse_str
line.
Still working with an URL syntax that looks like this: http://example.com/filename.html#var1=FOO&var2=BAR
Any solutions from you wizards? Thank you.
http://php.net/manual/en/function.parse-url.php
http://php.net/manual/en/function.parse-str.php
DEMO