What variable names can I use?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

What variable names can I use?

Post 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 !
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post by printf »

No, they must start with a-zA-Z / 127 - 255 ASCII or a under_score and can not contain characters like (~ ?`)

pif!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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).
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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 ~
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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.
Post Reply