 <p>An array printed out with <strong>print_r</strong> cannot be parsed back into a variable.</p> <p>In your server.php do <code>echo json_encode($_POST);</code>. Then in your client.php</p> <pre><code>&lt;?php //... $output = curl_exec($curl_handle); // and now you can output it however you like if ($this-&gt;request_response_type == 'array') { //though i don't see why you would want that as output is now useless if someone ought to be using the variable $outputVar = json_decode($output); // that parses the string into the variable print_r((array)$outputVar); // or even better use serialize() echo serialize($outputVar); } else if ($this-&gt;request_response_type == 'json') { echo $output; //this outputs the original json } else if ($this-&gt;request_response_type == 'xml') { // do your xml magic with $outputVar which is a variable and not a string //xml conversion will be done here later. not ready yet. } </code></pre>