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!!

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']);
Sign up to request clarification or add additional context in comments.

Comments

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']);

Comments

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.

Comments

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.

Comments

Your Answer

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.