php - Link with GET parameter -
in link can append parameters. if want add new parameter url has one.
example: old: example.php?hi=hello new: example.php?hi=hello&hello=hi
is there other way of doing way:
echo '<a href="'. $_server['request_uri'].'&hello=hi">';
the caveat detecting whether or not question mark exists or not. if doesn't, you'll need add it. quick , dirty way strpos:
if (strpos($_server['request_uri'], '?') === false) { $qspart = '?'; } else { $qspart = '&'; } $oldurl = $_server['request_uri']; echo '<a href="' . $oldurl . $qspart . 'hello=hi">';
a more robust method breaking down request_uri
, rebuilding after inspection using parse_url , http_build_query may beyond scope.
Comments
Post a Comment