Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 10 of 10

Thread: PHP variable within variable

  1. #1
    Vexir's Avatar
    4,185
    posts
    Coming and going.

    PHP variable within variable

    I have this variable: $somecontent

    I want to put the value of a bunch of other variables into it...

    I tried

    $somecontent = '$_POST[\'opponent\'] $_POST[\'type\'] $_POST[\'map\'] $_POST[\'winlose\']
    $_POST[\'yourscore\'] $_POST[\'theirscore\'] $_POST[\'mvp\']\n';

    But that just outputted (when echoed)

    $_POST[\'opponent\'] $_POST[\'type\'] $_POST[\'map\'] $_POST[\'winlose\']
    $_POST[\'yourscore\'] $_POST[\'theirscore\'] $_POST[\'mvp\']\n

    How come?

  2. #2
    do u want an array, or do u want to tie together the various variables to form one long string or wat?

  3. #3
    Vexir's Avatar
    4,185
    posts
    Coming and going.
    tie them together to form a string which is stored in $somecontent

  4. #4
    Uh... Maybe this is what you are looking for???
    PHP Code:
    $somecontent $_POST['opponent'] . $_POST['type'] . $_POST['map'] . $_POST['winlose'] . $_POST['yourscore'] . $_POST['theirscore'] . $_POST['mvp'] . '\n'
    CyanBlue / Jason Je / Flash Developer
    http://CyanBlue.FlashVacuum.com
    http://www.FlashVacuum.com

  5. #5
    Vexir's Avatar
    4,185
    posts
    Coming and going.
    Ahh yeah thanks a lot

  6. #6
    Just make sure that you need to use . (dot) to concatenate the strings in PHP... and that won't be that visible if you wear four eyes like I do...

    Glad to be of service...
    CyanBlue / Jason Je / Flash Developer
    http://CyanBlue.FlashVacuum.com
    http://www.FlashVacuum.com

  7. #7
    amitgeorge's Avatar
    646
    posts
    -1 posts per day. Huh ?
    btw the problem with your code was

    $somecontent = '$_POST[\'opponent\'] $_POST[\'type\'] $_POST[\'map\'] $_POST[\'winlose\']
    $_POST[\'yourscore\'] $_POST[\'theirscore\'] $_POST[\'mvp\']\n';

    should be

    $somecontent = "$_POST[opponent] $_POST[type] $_POST[map] $_POST[winlose]
    $_POST[yourscore] $_POST[theirscore] $_POST[mvp]\n";

    notice the quotes

  8. #8
    ekhrm...

    $somecontent = "$_POST['opponent'] $_POST['type'] $_POST['map'] $_POST['winlose']
    $_POST['yourscore'] $_POST['theirscore'] $_POST['mvp']\n";

  9. #9
    Vexir's Avatar
    4,185
    posts
    Coming and going.
    AH i see.

  10. #10
    amitgeorge's Avatar
    646
    posts
    -1 posts per day. Huh ?
    Quote Originally Posted by fluid_tw0
    ekhrm...

    $somecontent = "$_POST['opponent'] $_POST['type'] $_POST['map'] $_POST['winlose']
    $_POST['yourscore'] $_POST['theirscore'] $_POST['mvp']\n";
    whats ekhrm ?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012