以下 CURL 命令的 PHP 等效项是什么?
curl -X POST -d "html=<html><body><h1 style="color: red;">Hello World!</h1>" http://example.com/post"
尝试这样的事情:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/post');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
$data = array('html' => '<html><body><h1 style="color: red;">Hello World!</h1>');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);