cURL to PHP Converter
Convert curl commands to PHP code using cURL, Guzzle or Requests. Paste a command and the PHP snippet appears instantly — everything runs in your browser.
- Instant ConversionCode updates as you type
- Multiple Languages40 languages, 61 libraries
- 100% Client SideYour data stays private
How to use this tool
Steps for using the cURL to Code.
- Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
- Paste it into Enter cURL command. The PHP cURL code appears instantly; other PHP libraries (Guzzle, Requests) are in the tabs above the code.
- Set up: Make sure the
curlextension is enabled (it is in most PHP installs). - Run it: Run
php request.php, or use the code in your application. Replace placeholders such asYOUR_TOKENfirst, and check any notes under the editors for curl options that have no cURL equivalent.
Example
GET with headers → PHP cURL
curl 'https://api.example.com/v1/users?page=2' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN'<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.example.com/v1/users?page=2',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Accept: application/json',
'Authorization: Bearer YOUR_TOKEN',
],
]);
$response = curl_exec($ch);
if ($response === false) {
echo 'Error: ' . curl_error($ch) . PHP_EOL;
} else {
echo curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL;
echo $response . PHP_EOL;
}
curl_close($ch);Common use cases
- Plain PHP sites and WordPress plugins
- Scripts without Composer
Converting curl to PHP cURL
PHP's cURL extension wraps libcurl, so options map closely to the command line.
The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent cURL code. Options that have no cURL equivalent are listed under the editors rather than silently dropped.
Other libraries for PHP, each with its own page: Guzzle, Requests.
Limitations
- The code is a starting point: add timeouts, retries and error handling for production use.
- Secrets in the curl command are copied into the code — move them to environment variables before committing.
Frequently asked questions
Is the PHP cURL extension enabled?
Usually. Check with php -m | grep curl; enable extension=curl in php.ini if it's missing.
cURL extension or Guzzle?
The extension needs no dependencies; Guzzle gives a cleaner API with Composer.
Is my curl command sent to a server?
No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.