About this tool
Paste a curl command and get working PHP. Choose the cURL extension built into PHP, with every option in one curl_setopt_array() call, or Guzzle, the most popular PHP HTTP client (composer require guzzlehttp/guzzle). JSON bodies become PHP arrays, so they’re easy to edit, and file uploads become CURLFile or a Guzzle multipart part.
Supported curl options
-X, -H, -d / --data / --data-raw / --data-binary / --data-urlencode, --json, -F (multipart), -u (Basic auth), -b (cookies), -A, -e, -G, -I, -L, -k and combined flags like -sSL. Bash quoting, $'…' strings and line continuations work, and so does Chrome DevTools’ “Copy as cURL (cmd)” output for Windows. Options without an equivalent, like -o or -v, are listed so nothing is silently lost.
Copy a request from the browser: open DevTools → Network, right-click a request → Copy → Copy as cURL, and paste it here.
Notes on the generated code
- Redirects: the cURL extension doesn’t follow them unless you set
CURLOPT_FOLLOWLOCATION; Guzzle does by default, so the code adds'allow_redirects' => falseunless your command used-L. - Errors:
curl_exec()returnsfalseon network failures, which the code turns into an exception; HTTP errors arrive as normal responses, so check$status. Guzzle throwsRequestExceptionfor 4xx and 5xx responses. - Insecure requests:
-kbecomesCURLOPT_SSL_VERIFYPEER => falseor'verify' => false. Use it only for local testing. - Since PHP 8,
curl_close()isn’t needed: the handle is freed automatically.
FAQ
How do I convert a curl command to PHP?
Paste it above and choose the cURL extension or Guzzle. The PHP code appears instantly.
How do I send JSON with PHP cURL?
Set CURLOPT_POSTFIELDS to json_encode($data) and add a Content-Type: application/json header. The converter writes both.
Which is better, the cURL extension or Guzzle?
The extension needs no dependencies. Guzzle has a cleaner API, PSR-7 messages, middleware and async requests, and is used by Laravel’s HTTP client.
How do I upload a file?
curl -F "file=@photo.jpg" becomes new CURLFile('photo.jpg') for the extension or a multipart part with fopen() for Guzzle.