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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -