Re: Accessing superglobal elements
am 22.11.2007 21:47:20 von luiheidsgoeroe
On Thu, 22 Nov 2007 21:32:40 +0100, Michaelp wrote:
> Hello!
>
> I see that I can access a superglobal element using the index this
> way:
>
> print("$_GET[surname]
"); //(element index without any
> delimiters within a double-quotation-mark-delimited string)
>
> But not this way:
>
> print("$_GET['surname']
"); //(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,
> expecting T_STRING or T_VARIABLE or T_NUM_STRING
>
>
> Why is that? (I cant understand why PHP gets confused by that)
Posted the links only days ago, but here you go:
http://nl2.php.net/manual/en/language.types.string.php#langu age.types.string.parsing
So, use:
"{$_GET['surname']}
"
(Well, actually, don't, unless you're sure you've checked the GET variable
for XSS attacks.
--
Rik Wasmus
Re: Accessing superglobal elements
am 23.11.2007 17:03:33 von Acrobatic
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:
http://www.iamcal.com/publish/articles/php/processing_html_p art_2/
On Nov 22, 2:47 pm, "Rik Wasmus" wrote:
> On Thu, 22 Nov 2007 21:32:40 +0100, Michaelp wrote:
> > Hello!
>
> > I see that I can access a superglobal element using the index this
> > way:
>
> > print("$_GET[surname]
"); //(element index without any
> > delimiters within a double-quotation-mark-delimited string)
>
> > But not this way:
>
> > print("$_GET['surname']
"); //(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,
> > expecting T_STRING or T_VARIABLE or T_NUM_STRING
>
> > Why is that? (I cant understand why PHP gets confused by that)
>
> Posted the links only days ago, but here you go:http://nl2.php.net/manual/en/language.types.string.php#la nguage.types...
>
> So, use:
> "{$_GET['surname']}
"
>
> (Well, actually, don't, unless you're sure you've checked the GET variable
> for XSS attacks.
> --
> Rik Wasmus