Help with setting variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fartsniff

    Help with setting variables

    hello all,
    this is some code that i am using that "loops" through all of the variables
    that paypal
    ships back to me via ipn.

    for ($x=0; $x < count($postvars ); $x++)
    { $y=$x+1;
    $postkey = $postvars[$x];
    $postval = $$postvars[$x];
    $postipn.= "&" . $postkey . "=" . urlencode($post val);
    $mailipn.= $postkey . " = " . $postval . "\r\n";
    }

    i then email myself a copy of $mailipn and it contains everything i need.
    that part works fine.
    however, is it possible to set a variable using the names that were
    returned.
    for example, paypal sends me back "business", so i would like to set the
    value of $business
    equal to the value from the paypal post.

    normally i would do this:
    @$business = $_POST['business'];
    but since there are quite a few variables, and the names change (i.e.
    shopping carts, etc.)
    i would like to set them using the loop posted above (it returns them all).

    using the loop above, the "business" line looks like this when echoed:
    business = mybusiness@payp al.com

    so you see, it would nice to make a $business variable for later use in the
    script
    that contained mybusiness@payp al.com

    thanks.


  • R. Rajesh Jeba Anbiah

    #2
    Re: Help with setting variables

    "fartsniff" <fart@sniff.com > wrote in message news:<vgcd7sgqr a07c9@corp.supe rnews.com>...[color=blue]
    > hello all,
    > this is some code that i am using that "loops" through all of the variables
    > that paypal
    > ships back to me via ipn.[/color]

    paypal_post_var s_in_str = "";
    foreach($paypal _post_arr as $key=>$value)
    {
    $value = urlencode(strip slashes($value) );
    paypal_post_var s_in_str .= "&$key=$val ue";
    }

    If you need the value of "business", you may use like
    $paypal_post_ar r['business']

    ---
    "I have a dream that one day girls will be measured by the size of
    their brains than the shape of their flush"
    Email: rrjanbiah-at-Y!com

    Comment

    • fartsniff

      #3
      Re: Help with setting variables

      thank you for your help.

      "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@r ediffmail.com> wrote in message
      news:abc4d8b8.0 307042110.731f5 91c@posting.goo gle.com...[color=blue]
      > "fartsniff" <fart@sniff.com > wrote in message[/color]
      news:<vgcd7sgqr a07c9@corp.supe rnews.com>...[color=blue][color=green]
      > > hello all,
      > > this is some code that i am using that "loops" through all of the[/color][/color]
      variables[color=blue][color=green]
      > > that paypal
      > > ships back to me via ipn.[/color]
      >
      > paypal_post_var s_in_str = "";
      > foreach($paypal _post_arr as $key=>$value)
      > {
      > $value = urlencode(strip slashes($value) );
      > paypal_post_var s_in_str .= "&$key=$val ue";
      > }
      >
      > If you need the value of "business", you may use like
      > $paypal_post_ar r['business']
      >
      > ---
      > "I have a dream that one day girls will be measured by the size of
      > their brains than the shape of their flush"
      > Email: rrjanbiah-at-Y!com[/color]


      Comment

      • Jason Dumler

        #4
        Re: Help with setting variables

        R. Rajesh Jeba Anbiah wrote:[color=blue]
        > "fartsniff" <fart@sniff.com > wrote in message news:<vgcd7sgqr a07c9@corp.supe rnews.com>...
        >[color=green]
        >>hello all,
        >>this is some code that i am using that "loops" through all of the variables
        >>that paypal
        >>ships back to me via ipn.[/color]
        >
        >
        > paypal_post_var s_in_str = "";
        > foreach($paypal _post_arr as $key=>$value)
        > {
        > $value = urlencode(strip slashes($value) );
        > paypal_post_var s_in_str .= "&$key=$val ue";
        > }
        >
        > If you need the value of "business", you may use like
        > $paypal_post_ar r['business'][/color]

        Going one step further by using PHP's Variable Variables, you could do this:
        <?
        while (list($key, $val) = each($paypal_po st_arr)) {
        $$key = $val;
        // ^^ - using a variable variable
        }
        ?>

        which results in $business being equal to whatever the actual value is.
        The only problem is that you have to know what all the variable names
        are in order to access them.

        Jason


        Comment

        • Tom Thackrey

          #5
          Re: Help with setting variables


          On 4-Jul-2003, "fartsniff" <fart@sniff.com > wrote:
          [color=blue]
          > hello all,
          > this is some code that i am using that "loops" through all of the
          > variables
          > that paypal
          > ships back to me via ipn.
          >
          > for ($x=0; $x < count($postvars ); $x++)
          > { $y=$x+1;
          > $postkey = $postvars[$x];
          > $postval = $$postvars[$x];
          > $postipn.= "&" . $postkey . "=" . urlencode($post val);
          > $mailipn.= $postkey . " = " . $postval . "\r\n";
          > }
          >
          > i then email myself a copy of $mailipn and it contains everything i need.
          > that part works fine.
          > however, is it possible to set a variable using the names that were
          > returned.
          > for example, paypal sends me back "business", so i would like to set the
          > value of $business
          > equal to the value from the paypal post.
          >
          > normally i would do this:
          > @$business = $_POST['business'];
          > but since there are quite a few variables, and the names change (i.e.
          > shopping carts, etc.)
          > i would like to set them using the loop posted above (it returns them
          > all).
          >
          > using the loop above, the "business" line looks like this when echoed:
          > business = mybusiness@payp al.com
          >
          > so you see, it would nice to make a $business variable for later use in
          > the
          > script
          > that contained mybusiness@payp al.com[/color]

          Import variables into the current symbol table from an array


          --
          Tom Thackrey

          Comment

          Working...