|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I am trying to find the documentation on how and why "id" is quoted in
the first example, but not in the second. ..............elseif($_GET['id'] == 'pro')............ .............."http://www.xxx.xxx.edu/~xxx/app_upd_2.php?id= $_GET[id]&key=$_GET[key]";............ I found this, but it doesnt really tell me why the first id HAS to have single qoutes and the second CAN'T: When a string is specified in double quotes or with heredoc, variables are parsed within it. I'm just looking for the official explanation. Thanks Mike |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Mike wrote:
> I am trying to find the documentation on how and why "id" is quoted in > the first example, but not in the second. > > .............elseif($_GET['id'] == 'pro')............ > > ............."http://www.xxx.xxx.edu/~xxx/app_upd_2.php?id= > $_GET[id]&key=$_GET[key]";............ > > I found this, but it doesnt really tell me why the first id HAS to > have single qoutes and the second CAN'T: > When a string is specified in double quotes or with heredoc, variables > are parsed within it. > > I'm just looking for the official explanation. > Thanks > Mike > The second instance is incorrect and should produce an E_NOTICE. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Dec 12, 9:29 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Mike wrote: > > I am trying to find the documentation on how and why "id" is quoted in > > the first example, but not in the second. > > > .............elseif($_GET['id'] == 'pro')............ > > > ............."http://www.xxx.xxx.edu/~xxx/app_upd_2.php?id= > > $_GET[id]&key=$_GET[key]";............ > > > I found this, but it doesnt really tell me why the first id HAS to > > have single qoutes and the second CAN'T: > > When a string is specified in double quotes or with heredoc, variables > > are parsed within it. > > > I'm just looking for the official explanation. > > Thanks > > Mike > > The second instance is incorrect and should produce an E_NOTICE. > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > JDS Computer Training Corp. > jstuck...@attglobal.net > ==================- Hide quoted text - > > - Show quoted text - No, it doesnt, in fact it will only work that way.I'm sure because I spent hours on it. And I copied it from my working file. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Dec 12, 9:45 pm, Mike <ampel...@gmail.com> wrote:
> On Dec 12, 9:29 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote: > > > > > > > Mike wrote: > > > I am trying to find the documentation on how and why "id" is quoted in > > > the first example, but not in the second. > > > > .............elseif($_GET['id'] == 'pro')............ > > > > ............."http://www.xxx.xxx.edu/~xxx/app_upd_2.php?id= > > > $_GET[id]&key=$_GET[key]";............ > > > > I found this, but it doesnt really tell me why the first id HAS to > > > have single qoutes and the second CAN'T: > > > When a string is specified in double quotes or with heredoc, variables > > > are parsed within it. > > > > I'm just looking for the official explanation. > > > Thanks > > > Mike > > > The second instance is incorrect and should produce an E_NOTICE. > > > -- > > ================== > > Remove the "x" from my email address > > Jerry Stuckle > > JDS Computer Training Corp. > > jstuck...@attglobal.net > > ==================- Hide quoted text - > > > - Show quoted text - > > No, it doesnt, in fact it will only work that way.I'm sure because I > spent hours on it. And I copied it from my working file.- Hide quoted text - > > - Show quoted text - To be more specific: if (isset($_SERVER['QUERY_STRING'])) { $newquerystring = "http://www.xxxxxx.xxxxxxxx.edu/~xxxxxxx/ app_upd_2.php?id=$_GET[id]&key=$_GET[key]"; $updateGoTo = $newquerystring; } header(sprintf("Location: %s", $updateGoTo)); } |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Mike wrote:
> I am trying to find the documentation on how and why "id" is quoted in > the first example, but not in the second. > > .............elseif($_GET['id'] == 'pro')............ > > ............."http://www.xxx.xxx.edu/~xxx/app_upd_2.php?id= > $_GET[id]&key=$_GET[key]";............ > > I found this, but it doesnt really tell me why the first id HAS to > have single qoutes and the second CAN'T: > When a string is specified in double quotes or with heredoc, variables > are parsed within it. > > I'm just looking for the official explanation. > Thanks > Mike When inside double quotes, PHP doesn't look for defined constants so you don't need to enclose associative array keys in quotes... unless you bracket them: --code-- error-reporting(E_ALL); // everyone knows this constant so we'll use it. $arr['E_ALL'] = 'world'; // array key is 'E_ALL' not E_ALL echo "Hello $arr[E_ALL].<br>"; // no errors - PHP does not confuse them. echo "Hello {$arr['E_ALL']}.<br>"; // no errors - PHP does not confuse them. echo "Hello {$arr[E_ALL]}.<br>"; // now errors - PHP assumes the defined constant. echo "Hello ".$arr[E_ALL]."<br>"; // now errors - PHP assumes the defined constant. --end code-- In example #1 the array key name is technically already quoted by the double quotes (in which php scans for variables) so quotes are not needed.PHP does not look for defined constants while inside double quotes. In example #2, the array variable has been isolated with brackets (which tells PHP to resolve the variable as if it were not in double quotes and so requires quotes around the key name or PHP assumes the defined constant. Examples #3 & #4 show the errors that are thrown when quotes are not used properly. It's all in the quotes and brackets: echo "Hello $arr[E_ALL]"; echo "Hello ".$arr['E_ALL']; echo "Hello {$arr['E_ALL']}"; ....all have the same output. Also to wrap up, you need to use brackets for multi-dimensional arrays when inside double quotes: $arr['cars']['chevy'] = 'Corvette'; echo "MY favorite car is the $arr[cars][chevy].<br>"; ....will not have the desired output but (php only sees the first dimension of the array), echo "MY favorite car is the {$arr['cars']['chevy']}.<br>"; ....does. --- Norm |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
..oO(Mike)
>I am trying to find the documentation on how and why "id" is quoted in >the first example, but not in the second. > >.............elseif($_GET['id'] == 'pro')............ > >............."http://www.xxx.xxx.edu/~xxx/app_upd_2.php?id= >$_GET[id]&key=$_GET[key]";............ > >I found this, but it doesnt really tell me why the first id HAS to >have single qoutes and the second CAN'T: >When a string is specified in double quotes or with heredoc, variables >are parsed within it. > >I'm just looking for the official explanation. It's described in the array type section. See the third example there: http://www.php.net/manual/en/languag...es.array.donts Micha |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Dec 12, 11:07 pm, Michael Fesser <neti...@gmx.de> wrote:
> .oO(Mike) > > >I am trying to find the documentation on how and why "id" is quoted in > >the first example, but not in the second. > > >.............elseif($_GET['id'] == 'pro')............ > > >............."http://www.xxx.xxx.edu/~xxx/app_upd_2.php?id= > >$_GET[id]&key=$_GET[key]";............ > > >I found this, but it doesnt really tell me why the first id HAS to > >have single qoutes and the second CAN'T: > >When a string is specified in double quotes or with heredoc, variables > >are parsed within it. > > >I'm just looking for the official explanation. > > It's described in the array type section. See the third example there: > > http://www.php.net/manual/en/languag...language.types.... > > Micha Great ! Thanks Mike |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On Thu, 13 Dec 2007 05:07:24 +0100, Michael Fesser wrote...
> >.oO(Mike) > >>I am trying to find the documentation on how and why "id" is quoted in >>the first example, but not in the second. >> >>.............elseif($_GET['id'] == 'pro')............ >> >>............."http://www.xxx.xxx.edu/~xxx/app_upd_2.php?id= >>$_GET[id]&key=$_GET[key]";............ >> >>I found this, but it doesnt really tell me why the first id HAS to >>have single qoutes and the second CAN'T: >>When a string is specified in double quotes or with heredoc, variables >>are parsed within it. >> >>I'm just looking for the official explanation. > >It's described in the array type section. See the third example there: > >http://www.php.net/manual/en/languag...es.array.donts > >Micha Since I started off learning Perl before PHP, I had gotten into the habit of quoting any array keys that weren't numeric or a variable. Thanks for the link. Tom -- NewsGuy Accounts Go Jumbo! NewsGuy Express increased from 30 to 50 GB of download capacity http://newsguy.com/overview.htm |
|
![]() |
| Outils de la discussion | |
|
|