cURL to PHP (cURL) Converter

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

Key Facts

Category
Developer & Web
Input Types
textarea, checkbox
Output Type
text
Sample Coverage
4
API Ready
Yes

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.

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.

Examples

1. Converting a JSON POST Request

Backend Developer
Background
A developer needs to integrate a payment gateway API that only provides cURL examples in its documentation.
Problem
Manually writing the curl_setopt array for a POST request with custom headers and a JSON payload is tedious and error-prone.
How to Use
Paste the cURL command containing -X POST, -H 'Content-Type: application/json', and -d '{"amount": 100}' into the input field, keep 'Pretty-print body' enabled, and copy the generated PHP code.
Example Config
curlCommand: curl -X POST https://api.stripe.com/v1/charges -H "Authorization: Bearer sk_test" -H "Content-Type: application/json" -d '{"amount": 100, "currency": "usd"}'
prettyBody: true
includeComments: true
Outcome
A complete PHP script using curl_init(), setting CURLOPT_POSTFIELDS with the JSON string, configuring the authorization headers, and executing the request.

2. Translating a GET Request with Custom Headers

Systems Integrator
Background
An integrator is debugging a connection to an internal microservice and has a working cURL command with custom authentication headers.
Problem
The command needs to be executed programmatically within a legacy PHP cron job.
How to Use
Input the cURL command with multiple -H flags into the converter and disable the 'Include comments' option for a more compact output.
Example Config
curlCommand: curl -H "X-Api-Key: secret123" -H "Accept: application/json" https://internal.service/data
prettyBody: false
includeComments: false
Outcome
A clean PHP snippet containing only the necessary curl_setopt configurations for the URL and headers, ready to be pasted directly into the cron script.

Try with Samples

development

Related Hubs

FAQ

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.

API Documentation

Request Endpoint

POST /en/api/tools/curl-to-php

Request Parameters

Parameter Name Type Required Description
curlCommand textarea Yes -
prettyBody checkbox No -
includeComments checkbox No -

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-curl-to-php": {
      "name": "curl-to-php",
      "description": "Convert a cURL command into a PHP cURL code snippet with curl_setopt, headers, and post fields",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=curl-to-php",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]