HTTP POST in PHP5

Called with an associative array of parameters to POST:

function post($url, $data){
  $file = @file_get_contents($url, NULL, stream_context_create(array('http' => array('method' => 'POST', 'content' => http_build_query($data)))));
  return $file ? $file : "Error POSTing to $url";
}

print post('http://server.example.com/form', array('foo' => 'rhubarb'));

Comments

All fields are optional, email address will not be shown; no HTML, URLs are automatically hyperlinked.