tags:

views:

69

answers:

4

How can you match the following figure in $_GET by PHP?

I have the following URL

<a href="?questions&777">To solve this problem in PHP</a>

The number "777" changes for each question. I know that you can get the first parameter by if(array_key_exists('questions', $_GET) { -- // do this --}.

However, I am not sure how you can refer to the figure. The same would be something like [0-9]{1-9} in Perl.

+1  A: 

You separate parameters using & and not ?:

<a href="?questions=blah&thenumber=777">To solve this problem in PHP</a>

The question mark means the beginning of a query string, after which a bunch of names and values (e.g. somename=somevalue) separated by an ampersand are expected.

karim79
@karim: I do not want to show the `thenumbe=` for the reader. **How can you match only the number when you have the URL such as "questions/777"?**
Masi
+3  A: 

Can you change the link to be

<a href="?questions=777">

Then it's as simple as looking at the value of $_GET['questions']. Otherwise you'll need to use the $_SERVER variable to look at the string url used to call the page.

Cahlroisse
+1  A: 

The easiest would be to to use:

<a href="?questions=777">To solve this problem in PHP</a>

and then use the value of $_GET['questions']

Peter Olsson
+1  A: 

Example:

<a href="index.php?do=post&question=How+to+do+this...">How to do this?</a>

$_GET['do']; // = post
$_GET['question']; // = How to do this...
Alix Axel