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
- Emits a curl_init() handle configured with a single curl_setopt_array() call
- Sets CURLOPT_CUSTOMREQUEST to the method inferred from the curl flags
- Maps -H/--header flags into a CURLOPT_HTTPHEADER array of Name: Value strings
- Sends the request body through CURLOPT_POSTFIELDS
- Turns -u/--user into a Basic auth header and handles cookies, user-agent, and referer
- Appends -G/--get data to the URL as a query string
- Returns the body with CURLOPT_RETURNTRANSFER and reads the status with curl_getinfo
- Copy the result or download it as request.php with one click
How to use the cURL to PHP
- Paste your curl command into the cURL command box.
- Read the generated PHP cURL script in the output panel.
- Check the warning banner for any flags that were adjusted or skipped.
- 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
- Call to undefined function curl_init(). — The PHP cURL extension is not enabled. Install or enable ext-curl (for example php-curl on Debian/Ubuntu) and restart PHP.
- curl_exec returns false instead of a response. — An error occurred on the handle. Add curl_error($ch) before curl_close to see why, and check the URL, TLS, and headers.
- Headers in CURLOPT_HTTPHEADER are ignored by the server. — Each entry must be a single "Name: Value" string. The converter formats them that way; keep the colon and space if you edit them.
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
- cURL to Python — Convert a curl command to Python requests code.
- cURL to Go — Convert a curl command to Go net/http code.
- cURL to Node.js (axios) — Convert a curl command to Node.js axios code.
- cURL to Fetch — Convert a curl command to a JavaScript fetch() call.
- API Request Client — Send HTTP requests, build headers and params, inspect responses — your last 25 requests are saved locally.
- URL Parser — Break a URL into its parts and list query parameters.
All ArrayKit tools