How to Post Data to Remote Server Using PHP

We usually post data to remote server by form in browser. and how can we simulate this action by php?  Source code below give us an example.

 $postData = array();
 $postData['data1'] = "testdata1";
 $postData['data2'] = "testdata2";
 $postData['data3'] = "testdata3";
 foreach ($postData as $k=>$v)
 $str.= "$k=".urlencode($v)."&";
 $c = curl_init();
 curl_setopt($c, CURLOPT_POST, 1);
 curl_setopt($c, CURLOPT_HEADER, 0);
 curl_setopt($c, CURLOPT_URL,$url);
 curl_setopt($c, CURLOPT_POSTFIELDS, $postData);
 $result = curl_exec($c);