Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #11197

Re: pass variable in php construct

Date 2011-02-04 17:29 +0100
From Luuk <Luuk@invalid.lan>
Newsgroups comp.lang.php
Subject Re: pass variable in php construct
References <6af4aa93-3f68-4afd-a0a0-a19e021cc829@k16g2000vbq.googlegroups.com> <iidie7$3q9$1@news.eternal-september.org> <ag7ok6di260i097e9131ctlvq0kc0pgsqg@mfesser.de>
Message-ID <e4mt18-ms9.ln1@luuk.invalid.lan> (permalink)

Show all headers | View raw


On 04-02-11 16:42, Michael Fesser wrote:
> .oO(Curtis Dyer)
> 
>> Joe <juliani.moon@gmail.com> wrote:
>>
>>> I have these simple lines in my php script:
>>>
>>> <?php
>>> if (!empty($_GET[req])) {
>>
>> You need quotes around ``req''.
> 
> Yes.
> 
>>>            print "<h2>$_GET[req]</h2>";
>>
>> Here, too.
> 
> No. Note the double quotes around the string. Quotes around the array
> key are not allowed here, unless you use curly syntax. So both of these
> ways are correct:
> 
> print "<h2>$_GET[req]</h2>";
confusing syntax this is.....

But it works, and even better:
print "<h2>$_GET['req']</h2>";  <== produces an error
(PHP Parse error:  syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING)


> print "<h2>{$_GET['req']}</h2>";
> 
> Micha


-- 
Luuk

Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: pass variable in php construct Michael Fesser <netizen@gmx.de> - 2011-02-04 16:42 +0100
  Re: pass variable in php construct sheldonlg <sheldonlg@thevillages.net> - 2011-02-04 17:17 -0500
  Re: pass variable in php construct Curtis Dyer <dyer85@gmail.com> - 2011-02-04 22:11 +0000
  Re: pass variable in php construct Luuk <Luuk@invalid.lan> - 2011-02-04 17:29 +0100

csiph-web