Re: Re: Variables within a string
| From: | Analysis & Solutions | Date: | Tue, 12 Mar 2002 03:11:50 +0000 |
| Subject: | Re: Re: Variables within a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-88136@lists.php.net to get a copy of this message | ||
On Mon, Mar 11, 2002 at 08:39:16PM -0500, webapprentice wrote:
> From: Jason Wong <php-general@gremlins.com.hk>
> On Monday 11 March 2002 11:10, Chris Cocuzzo wrote:
> >
> > $foo = "Entry for " . $HTTP_POST_VARS["name"];
>
> $foo = "Entry for for $HTTP_POST_VARS[name]";
But that's not good programming. Associative arrays should have the key
quoted in order to avoid confusion with contants. See
http://www.php.net/manual/en/language.types.array.php#language.types.array.donts
Plus, since you're using non-evaluated strings, use single quotes.
So, I'd write it like this:
$foo = 'Entry for for ' . $HTTP_POST_VARS['name'];
But, wouldn't it be cleaner to just use?:
$foo = "Entry for for $name";
Now, I wonder why you're even assigning this information to yet another
varialbe. Why not just use the information straight up?:
echo "Entry for for $name";
Of course, there are legitimate reasons for your approach, but often new
programmers needlessly assign stuff to varialbes. Just making sure.
Finally, if you really want to use $HTTP_POST_VARS[] AND your'e
running PHP 4.1*, consider using the superglobal $_POST[] instead.
Enjoy,
--Dan
--
PHP scripts that make your job easier
http://www.analysisandsolutions.com/code/
SQL Solution | Layout Solution | Form Solution
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y