RE: [PHP] function definition causing problems?
| From: | Ford, Mike [LSS] | Date: | Mon, 24 Jun 2002 17:30:31 +0000 |
| Subject: | RE: [PHP] function definition causing problems? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-103630@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Erik Price [mailto:pricee@hhbrown.com]
> Sent: 24 June 2002 18:12
>
> On Monday, June 24, 2002, at 12:15 PM, Johnson, Kirk wrote:
>
> > When you echo out an array element, the name needs to be enclosed in
> > curlies, e.g.,
> >
> > echo {$_SERVER['PHP_SELF']}
>
> I think that this is only important when using an associative array
> element reference within certain kinds of quotes. Like this:
>
> // this won't work b/c of quoting issues
> echo "This script is called $_SERVER["PHP_SELF"]";
>
> // this should work fine IIRC
> echo "This script is called $_SERVER['PHP_SELF']";
Nope. Quoted array indexes don't work inside strings.
> // this should also work if for some reason you needed
> // to use double quotes within the array element reference
> // (to interpolate a variable, for instance)
> echo "This script is called {$_SERVER["PHP_SELF"]}";
Nope. The {} don't change the quoting issues you mentioned in your first (non-working)
example.
> // and this is the same thing really
> echo "This script is called ${_SERVER["PHP_SELF"]}";
... and fails for the same reason!
You can use:
echo "This script is called {$_SERVER['PHP_SELF']}";
echo "This script is called ${_SERVER['PHP_SELF']}";
echo "This script is called $_SERVER[PHP_SELF]";
or even
echo "This script is called " . $_SERVER['PHP_SELF'];
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211