Bluehost.com Web Hosting $6.95

RE: [PHP] String construction help required please

This is a discussion on RE: [PHP] String construction help required please within the PHP General forums, part of the PHP Programming Forums category; [snip] > I need to display : "$_POST[$var]," > > Including the "" and the , . > > ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-01-2003
Jay Blanchard
 
Posts: n/a
Default RE: [PHP] String construction help required please

[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'].',"';
Reply With Quote
  #2 (permalink)  
Old 12-01-2003
Wouter Van Vliet
 
Posts: n/a
Default RE: [PHP] String construction help required please

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:09 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0