RE: [PHP] String construction help required please

From: Date: Mon, 01 Dec 2003 14:40:51 +0000
Subject: RE: [PHP] String construction help required please
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-171467@lists.php.net to get a copy of this message
Jay Blanchard wrote: > [snip] >> I need to display : "$_POST[$var]," >> >> Including the "" and the , . >> >> I have tried : \"\"$_POST[\".$var.\"]," but that is very wrong. >> >> Could one of you kind list members show me what it should be please ? > > > You have a couple of options... just pick the one that suits you... > > <? > echo "\"{$_POST[$var]},\""; > echo '"'.$_POST[$var].',"'; >> > [/snip] > > var should not have a $ in front of it, should it? > > echo "\"{$_POST['var']},\""; > echo '"'.$_POST['var'].',"'; That all depends. Consider the following: Assume: <input type='text' name='something' value='foo'> to be posted to the script print '"$_POST[$var],"'; // prints (literally): "$_POST[$var]," print '"'.$_POST['something'].","; // prints: "foo," print '"'.$_POST[$var].","; // Issues a 'notice: undefined index..' and prints: "," $var = 'something'; print '"'.$_POST[$var].","; // prints: "foo," Pick your flavor. Wouter

« previous php.general (#171467) next »