Convert curl to PHP

Paste your curl command below — the PHP · cURL code is generated instantly, entirely in your browser.

// your code will appear here

How the curl to PHP conversion works

The generated code uses PHP's cURL extension: the URL goes to CURLOPT_URL, headers become a CURLOPT_HTTPHEADER array, -d becomes CURLOPT_POSTFIELDS, and -u becomes CURLOPT_USERPWD.

Example

curl -X POST https://api.example.com/login \
  -H 'Content-Type: application/json' \
  -d '{"user": "alice", "pass": "secret"}'

becomes:

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.example.com/login");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"user\":\"alice\",\"pass\":\"secret\"}");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/json",
]);

$response = curl_exec($ch);