开发者

PHP $_GET URL's

I'm trying to do something with PHP with the $_GET values but I it seems impossible, for example:

?id=15&lang=en

?id=15 is the page &lang=en site language

I would like t开发者_StackOverflow社区his one

?id=15,en instead of using &lang=en I want to replace the &lang= with comma (,)

How can I do this in PHP or is it possible to try with a .htaccess configuration?


If you have an URL such as this one :

http://.../temp.php?id=15,en

$_GET will contain an array with only one item :

array
  'id' => string '15,en' (length=5)

Which means you'll have to extract the relevant data from that $_GET['id'] entry.


For example, you could use something like this :

$items = explode(',', $_GET['id']);
if (count($items) === 2) {
    list($id, $lang) = $items;
    echo "id : $id<br>";
    echo "lang : $lang<br>";
}

Using explode() to split the $_GET['id'] string, using a comma as the separator.

And you'd get the following output :

id : 15
lang : en


Of course, to get URLs with only one id parameter, you will have to modify the way your application generates URLs.

About that, there is not much we can do without knowing how you currently generate your URLs...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜