Skip to content
koducathome

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.

How to use this tool

Steps for using the cURL to Code.

  1. Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
  2. Paste it into Enter cURL command. The PHP cURL code appears instantly; other PHP libraries (Guzzle, Requests) are in the tabs above the code.
  3. Set up: Make sure the curl extension is enabled (it is in most PHP installs).
  4. Run it: Run php request.php, or use the code in your application. Replace placeholders such as YOUR_TOKEN first, and check any notes under the editors for curl options that have no cURL equivalent.

Example

GET with headers → PHP cURL

curl command
curl 'https://api.example.com/v1/users?page=2' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN'
PHP cURL
<?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.