0

Dear people,

There is any function instead of explode which does not add an index in the beginning of every line?

Instead of show:
[0] => Number=0
[1] => Number1=1
[2] => Number2=2

Shows like that:
Number=0
Number1=1
Number2=2

or some function that removes the [0], [1],[2]...

Thanks in advance!
Daniel

2
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by coleguitajuan
0
$post_url = "https://process.netpay-intl.com/member/remote_charge.asp";
$post_string = "";

foreach($post_values as $key => $value)
  {
     $post_string .= "$key=" . urlencode($value) . "&"; 
  }
$post_string = rtrim($post_string, "& ");

$request = curl_init($post_url);
     curl_setopt($request, CURLOPT_HEADER, 0);
     curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($request, CURLOPT_POSTFIELDS, $post_string);
     curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE);
     $post_response = curl_exec($request);

$response_array = explode("&", $post_response);
0

Make sure you use [code] tags. It makes code easier to read.

As for your problem.

$response = array();
foreach( explode( '&',$post_response ) as $data ) {
    list( $key,$val ) = explode( '=',$data );
    $response[$key] = $val;
}
echo '<pre>' . print_r( $response,true ) . '</pre>';

Just ran that. I think its what you are looking for.

Also, look into these functions. parse_str() and http_build_query() - PHP 5 only. I personally haven't used them, but they should help simplify some of your code.

Edited by Dani: Formatting fixed

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.