Page 1 of 1

What variable names can I use?

Posted: Thu Jun 15, 2006 5:37 pm
by tecktalkcm0391
Can I use PHP with a variable name of ~? This is for a live site so I don't want to mess around with it !

Posted: Thu Jun 15, 2006 5:48 pm
by printf
No, they must start with a-zA-Z / 127 - 255 ASCII or a under_score and can not contain characters like (~ ?`)

pif!

Posted: Thu Jun 15, 2006 5:58 pm
by feyd
I love the manual. The manual is this wonderful thing that has lots of information, including what a variable can and cannot be.
The Manual wrote: Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

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. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
  • Note: For our purposes here, a letter is a-z, A-Z, and the ASCII characters from 127 through 255 (0x7f-0xff).

Posted: Thu Jun 15, 2006 6:17 pm
by tecktalkcm0391
Well if I had a page url of

page.php/~variable

could I use $_GET[''] to get the ~variable and then take of the ~

Posted: Thu Jun 15, 2006 6:31 pm
by Chris Corbyn
tecktalkcm0391 wrote:Well if I had a page url of

page.php/~variable

could I use $_GET[''] to get the ~variable and then take of the ~
Yes. Use apache's mod_rewrite or set the query_string_separator in php.ini.

Posted: Thu Jun 15, 2006 8:17 pm
by tecktalkcm0391
What happens if I don't do:
Use apache's mod_rewrite or set the query_string_separator in php.ini.
Will it still work if the url is

page.php?~jdaflkdsjl

the $_GET['~']; would work?

Posted: Thu Jun 15, 2006 8:21 pm
by John Cartwright
tecktalkcm0391 wrote:What happens if I don't do:
Use apache's mod_rewrite or set the query_string_separator in php.ini.
Will it still work if the url is

page.php?~jdaflkdsjl

the $_GET['~']; would work?
no.

Posted: Thu Jun 15, 2006 8:24 pm
by tecktalkcm0391
ok, well then i'll look up how to do the mod_rewrite thing... or can i just do the query_string_separator [how do i do that?] i searched the manual, either i didn't do a good job or i just can't find it or its not there.