curl to PHP Converter

Convert a curl command to PHP cURL code instantly in your browser. The command stays on your device.

Your curl command is converted to PHP locally in your browser and never uploaded, but avoid pasting real production tokens or credentials into any tool.

Need a JavaScript version too? Try cURL to Fetch.

About cURL to PHP

This curl to php converter turns a curl command into a PHP script that uses the built-in cURL extension, the same client most PHP developers already reach for when calling an API. It reads flags like -X, -H, -d, --data-raw, --json, -u, -b, and -G and emits a curl_init() handle configured through a single curl_setopt_array() call, with CURLOPT_HTTPHEADER for your headers and CURLOPT_POSTFIELDS for the body. The result returns the response via CURLOPT_RETURNTRANSFER and prints the HTTP status code, so it slots into a controller, a script, or a quick test. Use it to move a terminal curl request into PHP without remembering each CURLOPT_ constant. The conversion runs in your browser, so the command and any tokens in it are processed locally on your device and never uploaded.

Features

How to use the cURL to PHP

  1. Paste your curl command into the cURL command box.
  2. Read the generated PHP cURL script in the output panel.
  3. Check the warning banner for any flags that were adjusted or skipped.
  4. Click Copy, or download the file as request.php.

Example

Input

curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name":"Ada"}'

Output

<?php

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.example.com/users',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => '{"name":"Ada"}',
]);

$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo $status . "\n";
echo $response;

Headers become a CURLOPT_HTTPHEADER array and the body goes into CURLOPT_POSTFIELDS.

Common errors & troubleshooting

Frequently asked questions

How do I convert a curl command to PHP?
Paste the curl command into the input box and the converter renders a PHP cURL script on the right that you can copy or download as request.php.
Does the output use the PHP cURL extension or Guzzle?
It uses the native PHP cURL extension (curl_init, curl_setopt_array, curl_exec), so there is no Composer dependency to install.
How are request headers represented in the PHP code?
Each -H header becomes a single "Name: Value" string inside the CURLOPT_HTTPHEADER array that curl_setopt_array passes to the handle.
Where does the request body go in the generated PHP?
The body is assigned to CURLOPT_POSTFIELDS, and CURLOPT_CUSTOMREQUEST carries the HTTP method so it works for POST, PUT, PATCH, and DELETE.
Is my curl command uploaded when I convert it to PHP?
No. The curl to php conversion runs entirely in your browser, so the command and any credentials in it stay on your device.

Related tools

All ArrayKit tools