# cURL to PHP (cURL) Converter

Convert a cURL command into a PHP cURL code snippet with curl_setopt, headers, and post fields

> Canonical page: https://elysiatools.com/en/tools/curl-to-php

- **Category:** Development

- **Keywords:** curl, convert, php, curl_setopt, http, api, code generator, snippet

## Overview

The cURL to PHP Converter allows developers to instantly transform raw cURL commands into clean, ready-to-run PHP code snippets using the native PHP cURL extension. It automatically parses HTTP methods, headers, and request bodies, generating structured PHP scripts with options to format payloads and include helpful comments.

## Inputs

- **cURL Command** (textarea): curl -X POST https://api.example.com/users \ -H "Content-Type: application/json" \ -d '{"name":"Alice"}'
- **Pretty-print body** (checkbox)
- **Include comments** (checkbox)

## When to use

- When migrating API requests tested in the terminal or Postman into a PHP backend application.
- When writing custom PHP integration scripts that require specific HTTP headers, authentication, or POST payloads.
- When debugging API integrations and needing to quickly verify how a cURL command translates to native PHP curl_setopt configurations.

## How it works

- Paste your raw cURL command into the input area, including any headers, methods, or data flags.
- Toggle the formatting preferences, such as pretty-printing the request body or including explanatory comments in the output.
- Copy the generated PHP script which utilizes curl_init, curl_setopt_array, and curl_exec to perform the request.

## Use cases

- Converting third-party API documentation examples (usually provided in cURL) into PHP integration code.
- Automating form submissions by converting curl -F file uploads or form data into PHP-compatible POST fields.
- Generating boilerplate integration code for legacy PHP projects that do not use modern HTTP client packages.

## Frequently asked questions

### Does this tool support POST requests with JSON payloads?

Yes, it parses data flags like -d or --data and translates JSON payloads into PHP strings configured via CURLOPT_POSTFIELDS.

### How are HTTP headers handled in the generated PHP code?

Headers specified with -H or --header are collected into a PHP array and assigned to the CURLOPT_HTTPHEADER option.

### Can I disable comments in the generated PHP snippet?

Yes, you can uncheck the 'Include comments' option to generate a cleaner, production-ready code snippet.

### Does this tool support custom HTTP methods like PUT or DELETE?

Yes, custom methods specified via -X or --request are mapped directly to the CURLOPT_CUSTOMREQUEST option in PHP.

### Is my sensitive API key or token sent to a server?

No, the conversion is performed entirely in your browser, ensuring your authorization headers and tokens remain secure.

## Related tools

- [cURL to Go (net/http) Converter](https://elysiatools.com/en/tools/curl-to-go): Convert a cURL command into a Go net/http code snippet with http.NewRequest, headers, and body
- [cURL to JavaScript (axios) Converter](https://elysiatools.com/en/tools/curl-to-js-axios): Convert a cURL command into a JavaScript axios code snippet with config object, headers, and data
- [cURL to JavaScript (fetch) Converter](https://elysiatools.com/en/tools/curl-to-js-fetch): Convert a cURL command into a JavaScript fetch() code snippet with headers, body, and method
- [cURL to Python (requests) Converter](https://elysiatools.com/en/tools/curl-to-python): Convert a cURL command into a Python requests code snippet with headers, data, and method
- [API Contract Stress Tester](https://elysiatools.com/en/tools/api-contract-stress-tester): Generate boundary-value test cases from an OpenAPI 3.x document and optionally send them to a real backend to spot contract mismatches
- [Cron Expression Explainer](https://elysiatools.com/en/tools/cron-expression-explainer): Parse a 5-part / 6-part / Quartz cron expression into a plain-language schedule description, show the field-by-field breakdown, and list the next N execution times in any IANA timezone — with an AI-generated natural-language explanation in your language
- [Tailwind Color Palette Sync](https://elysiatools.com/en/tools/tailwind-color-palette-sync): Generate theme.extend.colors for tailwind.config.ts from HEX colors, with WCAG contrast levels and optional dark mode.
- [cURL Command to HAR Converter](https://elysiatools.com/en/tools/curl-to-har-converter): Convert a cURL command into a portable HAR 1.2 request entry.

## Samples

- [Web Image Processing Python Samples](https://elysiatools.com/en/samples/web-image-processing-python): Web Python image processing examples using PIL/Pillow including reading, saving, resizing, and format conversion
- [PHP Samples](https://elysiatools.com/en/samples/php): Essential PHP code examples for web development, including modern PHP 8+ features and frameworks
- [Android Image Processing Java Samples](https://elysiatools.com/en/samples/android-image-processing-java): Android Java image processing examples including reading/saving images, scaling, and format conversion
- [Android Image Processing Kotlin Samples](https://elysiatools.com/en/samples/android-image-processing-kotlin): Android Kotlin image processing examples including reading/saving images, scaling, and format conversion
