如何使用PHP创建cURL请求

如何使用PHP创建cURL请求,php,curl,shellcheck,Php,Curl,Shellcheck,所以我找到了这个代码: data=$(curl \ --silent \ --user-agent "ShellCheck@github.com/lollek/scripts-and-stuff" \ --data-urlencode "script@$file" \ "http://www.shellcheck.net/shellcheck.php") 以下是完整代码: 是否可以使用php发出相同的请求,如果可以,我如何做?我的意思是将代码($file)发送到shellch

所以我找到了这个代码:

data=$(curl \
  --silent \
  --user-agent "ShellCheck@github.com/lollek/scripts-and-stuff" \
  --data-urlencode "script@$file" \
  "http://www.shellcheck.net/shellcheck.php")
以下是完整代码:

是否可以使用php发出相同的请求,如果可以,我如何做?我的意思是将代码($file)发送到shellcheck.net/shellcheck.php并从中获取请求。有人知道吗

@编辑

我发现了这样的东西:

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => 'http://www.shellcheck.net/shellcheck.php'
));
$resp = curl_exec($curl);
curl_close($curl);
<?php
   if( $_REQUEST["code"])
   {
    echo "Your code: ". $_REQUEST['code']. "<br />";      
    $data = $_REQUEST['code'];
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "http://www.shellcheck.net/shellcheck.php"); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data); 
    $resp = curl_exec($curl);
    curl_close($curl);
    exit();
   }
?>
<html>
   <body>

      <form action="<?php $_PHP_SELF ?>" method="POST">
         Code: <input type="text" name="code" />
         <input type="submit" />
      </form>

   </body>
</html>
但是我怎样才能把我的$file发送到这里呢

@编辑2

现在我在尝试这样的事情:

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => 'http://www.shellcheck.net/shellcheck.php'
));
$resp = curl_exec($curl);
curl_close($curl);
<?php
   if( $_REQUEST["code"])
   {
    echo "Your code: ". $_REQUEST['code']. "<br />";      
    $data = $_REQUEST['code'];
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "http://www.shellcheck.net/shellcheck.php"); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data); 
    $resp = curl_exec($curl);
    curl_close($curl);
    exit();
   }
?>
<html>
   <body>

      <form action="<?php $_PHP_SELF ?>" method="POST">
         Code: <input type="text" name="code" />
         <input type="submit" />
      </form>

   </body>
</html>


是的,有可能。不,我们不会为你做的。我们不是代码翻译服务。你的回答非常有用……嗯,我认为@MarcB的回答是正确的。你可能不想发送$file的内容,而不是$file本身。在php中,将文件读入变量的一种方法,例如:$fileContent=file\u get\u contents($file)//$文件当然是实际文件的路径是的,我想发送文件或表单的内容:P,但我仍然不知道如何将此竞赛添加到curl数组中。