Accessing superglobal elements

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I see that I can access a superglobal element using the index this

print("<p>$_GET[surname]</p>"); //(element index without any
delimiters within a double-quotation-mark-delimited string)

But not this way:

print("<p>$_GET['surname']</p>"); //(apostroph-delimited element index
within a double-quotation-mark-delimited string)

The latter gives me an error message:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,

Why is that? (I cant understand why PHP gets confused by that)

Is this configurable?


Re: Accessing superglobal elements

Michaelp wrote:
Quoted text here. Click to load it

Actually, the first should give you a notice, also.  But you evidently  
have notices disabled.

And no, you can't configure it.  Just use curly braces, i.e.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Accessing superglobal elements

Quoted text here. Click to load it

Posted the links only days ago, but here you go:

So, use:

(Well, actually, don't, unless you're sure you've checked the GET variable  
for XSS attacks.
Rik Wasmus

Re: Accessing superglobal elements

Rik is right--the curly's {} will do what you want to do, and you
should clean your variables from the user. PHP has some built-in
methods, but Cal Henderson has an even better way to do this:

Quoted text here. Click to load it

Site Timeline