Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Let's say I am getting requests such as:

http://www.example.com/index.php?id=123&version=3&id=234&version=4

Is it possible to extract these in a simple way inside my php code? I realize I could get the entire querystring with javascript using window.location.href and handle it manually but I'm looking for something more elegant. The requests can contain any number of version/id pairs but I can assume that the query is well-formed and have no obligation to handle invalid strings.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
220 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you can change the field name to include [], then PHP will create an array containing all of the matching values:

http://www.example.com/index.php?id[]=123&version[]=3&id[]=234&version[]=4

If you don't have the ability to change the field names, then as you say, you'll have to parse the querystring yourself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...