Question: Update
------

In my original post I seem to have implied my variable name has a hyphen. My issue seems to be with the htaccess file below not matching on a hyphen but my $\_GET variable content has a hyphen, not the variable itself.

original
--------

I originally referenced <http://php.net/manual/en/language.variables.variable.php> which a user stated it is not possible to reference a php variable (by $\_POST or $\_GET) with a hyphen but this was written in 2009.

In one of my URL's, I allow users to enter a unique ID as "www.site.com/id123" which the "id123" is picked up as a $\_GET variable with php. Some users have chosen to use "www.site.com/id-123" which does not work (no server error other than page cannot be found).

Any ideas on this?

.htaccess
---------

```
RewriteEngine On

#if file or directory do not exist, try as an unique id
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z]+)$ index?ID=$1 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [QSA,L]

```

Thinking through more, the rewrite rule above seems it may need modification to handle a hyphen request. Does this seem right?

Answer: 
In theory, [you cannot](http://www.php.net/manual/en/language.variables.basics.php):

> 
> Variable names follow the same rules
>  as other labels in PHP. A valid
>  variable name starts with a letter or
>  underscore, followed by any number of
>  letters, numbers, or underscores.
> 
> 
> 

In practice, well...

```
<?php

${'widh-hyphen'} = 'This variable has a pyphen';
${'Variable with funny name. Woot!'} = 'And this is even worse!';
var_dump(${'widh-hyphen'}, ${'Variable with funny name. Woot!'});

?>

```

... prints:

```
string(26) "This variable has a pyphen"
string(23) "And this is even worse!"

```

So I'd say you can.

Nothing of this should apply to GET and POST input data, though. Since [Register Globals](http://php.net/manual/en/security.globals.php) should always be disabled, your parameter become keys of the `$_GET` and `$_POST` associative arrays, and [other rules apply](http://www.php.net/manual/en/language.types.array.php):

> 
> A key may be either an integer or a
>  string. If a key is the standard
>  representation of an integer, it will
>  be interpreted as such (i.e. "8" will
>  be interpreted as 8, while "08" will
>  be interpreted as "08"). Floats in key
>  are truncated to integer. The indexed
>  and associative array types are the
>  same type in PHP, which can both
>  contain integer and string indices.
> 
> 
> 

In such case, you must only take into account that [dots are converted to underscores](http://www.php.net/manual/en/language.variables.external.php) for historical reasons:

> 
> Dots and spaces in variable names are
>  converted to underscores. For example
>  becomes
>  $\_REQUEST["a\_b"].
> 
> 
>
As Tom says, you're allowed hyphens in strings, so $\_GET[user] = 'id-123' won't give you any problems, nor will sending any data like get.php?user=id-123.

I assume your .htaccess will rewrite www.site.com//id-123 to /getuser.php?user=id-123
If so, you shouldn't have problems.

But if you're trying, for some reason to create $id-123 then you will have some issues..