0

Example:

Someone is currently on this page and want to change the language from lang=en to lang=fr:

 http:://domain.com/index.php?p=1&b=1&c=3&d=4&lang=en // I put two colons to disable the link here

How can I keep the rest of the value and just change the lang=en?

Remarks b=1&c=3&d=4 are conditional and may not exist (e.g. it could be only b=1&f=5 sometimes etc)

I can go as far as:

<a href="index.php?p=<?php echo $p; ?>&lang=fr">Change to French</a>

Do I have to go through all possible parameters like:

<?php
IF (ISSET($_REQUEST['b'])) { $b = '&b=' . ($_REQUEST['b']) } else { $b = ''; }
IF (ISSET($_REQUEST['c'])) { $c = '&c=' . ($_REQUEST['c']) } else { $c = ''; }
IF (ISSET($_REQUEST['d'])) { $d = '&d=' . ($_REQUEST['d']) } else { $d = ''; }
?>

<a href="index.php?p=<?php echo $p . $b . $c . $d; ?>&lang=fr">Change to French</a>

Thanks for teaching!

4

2 回答 2

2

You can generate query with http_build_query. Just add your $_REQUEST values into some array $query and add your lang value to its array. Or you can use only $_REQUEST array, but I think it is not good practice.

$query = $_REQUEST;
$query['lang'] = 'en';
$query_string = http_build_query($query);

Then just use your query string

于 2013-07-05T08:48:06.980 回答
0

Look at $_SERVER['QUERY_STRING'].

http://php.net/manual/en/reserved.variables.server.php

or Try,

$arr=$_GET;
$arr['lang']='fr';
<a href="index.php?<?php echo implode('&',$arr); ?>">Change to French</a>
于 2013-07-05T08:44:19.470 回答