3

I need to get the values out of a URL query string like this:

http://exmaple.com/?xyz.123

And assign them to variables inside index.php running on example.com, so that:

$name = xyz;
$number = 123;

How do I code this?

Thanks!!

asked Jul 14, 2011 at 21:41
2
  • Could just get the query value from $_SERVER["QUERY_STRING"] and then explode the value with the period which is seperating both values in your example Commented Jul 14, 2011 at 21:45
  • Do you mean ?xyz=123 ? This will form a key/value pair that you can access using $_GET. Commented Jul 14, 2011 at 21:48

4 Answers 4

8
list($name,$number) = explode('.',$_SERVER['QUERY_STRING']);
answered Jul 14, 2011 at 21:48
0
2

You can parse it with the following, though it is ripe for injection unless you perform some validation/sanitization afterwards:

list($name, $number) = explode('.', $_SERVER['QUERY_STRING']);

answered Jul 14, 2011 at 21:48
1

What you want to do is take a look at $_SERVER['QUERY_STRING']. Explode the query string by . to get an array of values. You can then set up the appropriate variables. Keep in mind you'll also probably want to do some validation on the data to ensure it's in the format you need.

answered Jul 14, 2011 at 21:45
0
0

You'd need to setup a mod_rewrite rule first like this (untested)...

RewriteRule ^([a-zA-Z]+)\.([0-9]+)$ index.php?name=1ドル&number=2ドル

Then you could pull them out from $_GET in PHP.

answered Jul 14, 2011 at 21:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.