469,267 Members | 1,113 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

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($postval);
$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 = my********@paypal.com

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

thanks.
Jul 16 '05 #1
4 3525
"fartsniff" <fa**@sniff.com> wrote in message news:<vg************@corp.supernews.com>...
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.


paypal_post_vars_in_str = "";
foreach($paypal_post_arr as $key=>$value)
{
$value = urlencode(stripslashes($value));
paypal_post_vars_in_str .= "&$key=$value";
}

If you need the value of "business", you may use like
$paypal_post_arr['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
Jul 16 '05 #2
thank you for your help.

"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab**************************@posting.google.c om...
"fartsniff" <fa**@sniff.com> wrote in message

news:<vg************@corp.supernews.com>...
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.


paypal_post_vars_in_str = "";
foreach($paypal_post_arr as $key=>$value)
{
$value = urlencode(stripslashes($value));
paypal_post_vars_in_str .= "&$key=$value";
}

If you need the value of "business", you may use like
$paypal_post_arr['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

Jul 16 '05 #3
R. Rajesh Jeba Anbiah wrote:
"fartsniff" <fa**@sniff.com> wrote in message news:<vg************@corp.supernews.com>...
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.

paypal_post_vars_in_str = "";
foreach($paypal_post_arr as $key=>$value)
{
$value = urlencode(stripslashes($value));
paypal_post_vars_in_str .= "&$key=$value";
}

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


Going one step further by using PHP's Variable Variables, you could do this:
<?
while (list($key, $val) = each($paypal_post_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
Jul 16 '05 #4

On 4-Jul-2003, "fartsniff" <fa**@sniff.com> wrote:
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($postval);
$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 = my********@paypal.com

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


http://www.php.net/manual/en/function.extract.php

--
Tom Thackrey
www.creative-light.com
Jul 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by arber | last post: by
8 posts views Thread by David McDivitt | last post: by
2 posts views Thread by sorobor | last post: by
8 posts views Thread by Eddie | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.