* Thus wrote Jeff Oien:
> I have items from a form that will be in $_POST that I want to send on.
> I'll be using this:
> $arr = array();
> 
> foreach($_POST as $key => $value) {
>       $arr[] = $key.'='.urlencode($value);
> }
> 
> $URL = "https://example.com/script.asp?".implode('&',$arr);
> header("Location: $URL\n");
> 
> However, there are a few variables I need changed. For example, the 
> people I'm sending it to need $rate_1m which is a mortgage rate but in 
> $_POST there is $rate_1m1 (the whole number) and $rate_1m2 (the two 
> numbers after the decimal). How do I get those two together and then 
> discard the two numbers and only send $rate_1m? If that makes any sense.

Instead of iterating through all the POST data, i would set up an
array of all the fields I need to pass to the other site:

$pass_fields = array('rate_1m', 'field2', 'field3');

Then iterate through those and fetch the appropriate POST variable
with some filtering:

foreach($pass_fields as $field) {

  switch ($field) {

    case 'rate_1m':
      $arr[] = 'rate1m1=' . urlencode($_POST['rate1m1'] . '.' $_POST['rate1m2']);
      break;

    default:
      $arr[] = urlencode($field) . '=' . urlencode($_POST[$field]);
      break;
  }

}
$URL = "https://example.com/script.asp?".implode('&',$arr);
      

Also, take note on the urlencode, it might be wise to do that.  A
note for PHP5 usage, simply defining a associative array will work:

$arr[$field] = $_POST['field'];
$URL = http_build_query($arr);


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to