Home Tools Blog About

Convert Curl to Php Curl

In short

Convert cURL to PHP curl_setopt() code. Auto-POST detection, JSON-safe parsing, basic auth, cookies, multipart. Free, offline, client-side, instant, secure.

  • Runs in your browser
  • Nothing uploaded
  • Free, no sign-up

Generate PHP curl_setopt() code from any cURL command. Handles JSON bodies with embedded quotes and sets the request method correctly even when -X is omitted.

🛡
100% PrivateNo server uploads, ever
InstantRuns in your browser
💧
No WatermarksClean output, always
🆓
Free ForeverNo accounts, no limits

How to Use Convert Curl to Php Curl

  1. Open Chrome DevTools → Network tab, right-click any request → Copy as cURL (bash).
  2. Paste into the left pane. Or click Load sample to see expected formats.
  3. Tick Include error handling to wrap with curl_errno() + throw new RuntimeException.
  4. Tick Auto json_decode if the API returns JSON - adds json_decode($response, true) + json_last_error() check.
  5. Change the PHP variable name from $ch if you already use that name in your code.
  6. Use Ctrl+Enter to re-convert. Live preview updates after 250 ms of inactivity.
  7. Copy or download the generated request.php.

Frequently Asked Questions

What flags are supported?

-X/--request, -H/--header, -d/--data, --data-raw, --data-binary, --data-urlencode, -u/--user (basic auth → CURLOPT_USERPWD + CURLAUTH_BASIC), -b/--cookie (→ Cookie header), -A/--user-agent, -e/--referer, -G/--get (build query string from -d), -F/--form (multipart → CURLFile), -L/--location, -k/--insecure, --compressed, --connect-timeout, --max-time.

How is multipart (-F) converted?

Each -F 'key=value' becomes an array entry: "key" => "value". Each -F 'file=@path/to/file.jpg' becomes "file" => new CURLFile("path/to/file.jpg") with a comment that the path is relative to the PHP cwd at execution time. You may need to use realpath() or an absolute path depending on your setup.

What about -G + -d?

cURL: curl -G 'https://api.com/search' -d 'q=hello' -d 'limit=10' → makes GET to https://api.com/search?q=hello&limit=10. The tool detects -G and appends the body parts to the URL as query string (preserving any existing ?...). No CURLOPT_POSTFIELDS emitted. Method stays GET.

How is the body escaped for PHP?

Single-quoted PHP string. Inside PHP single quotes only \ and \' need escaping – no variable interpolation, no n processing. So a JSON body like {"$ref":"x"} stays literally {"$ref":"x"} (PHP won’t try to interpolate $ref). For URL/header values, double-quoted strings are used with \, \", \$, \n, \r escaping.

What if my command uses Windows cmd quoting?

The tokenizer assumes POSIX/bash conventions: single-quoted = literal, double-quoted = backslash escapes active. Windows cmd uses different rules (double quotes only, ^ for escape, no single quotes). Convert your command to bash style first (Chrome DevTools “Copy as cURL (bash)” option works). Or run it under WSL/Git Bash.

Why CURLOPT_USERPWD + CURLAUTH_BASIC for -u?

Setting USERPWD without HTTPAUTH defaults to digest negotiation. Forcing CURLAUTH_BASIC matches the cURL CLI’s -u behaviour (which sends basic auth by default). Without explicit CURLAUTH_BASIC, PHP might attempt a digest dance the server doesn’t support.

Does it handle multi-line backslash continuation?

Yes. \ + newline is collapsed to a space before tokenisation. So this works: curl 'https://x.com' \
-H 'A: b' \
-d 'data'
. Also handles Windows-style \r\n line endings.

What’s not supported?

Not converted: --cert / --key / --cacert (you’d add CURLOPT_SSLCERT etc. manually with file paths), --proxy (would map to CURLOPT_PROXY but not implemented yet), -o/--output (PHP’s file_put_contents after exec is the equivalent), --resolve (DNS override). If you need these, add the corresponding curl_setopt calls after the generated code.

Is my data secure?

Yes. cURL input + generated PHP stay in your browser. No request is ever made, no data is logged. API keys, basic auth credentials, and Bearer tokens in your cURL never leave your device.

Keep going

Related Tools

All Developer tools →

Convert Curl to Fetch

Convert cURL to fetch/axios/node-fetch with TypeScript option. Handles auth, cookies, JSON body without double-encoding.…

Convert Curl to Python Requests

Convert cURL to Python requests/httpx/aiohttp. JSON-safe, auth, cookies, multipart. Free, offline, client-side, instant, secure.

Android AssetLinks JSON Generator - App Links

Android AssetLinks JSON Generator files for Android App Links. Configure package names and SHA-256…

Convert ASCII to Binary

Convert ASCII to Binary tool. Convert text to binary and binary to text. 100%…

Base32 Encoder/Decoder

Free Base32 encoder and decoder tool. Encode or decode Base32 strings online. 100% client-side,…

Base58 Encoder/Decoder

Free Base58 encoder and decoder tool. Encode or decode Base58 strings like Bitcoin addresses.…

Base64 Encoder and Decoder

Base64 Encoder and Decoder - Convert text strings into Base64 format or decode Base64…

BBCode to HTML Converter

Generate standard semantic HTML arrays translating classic forum BBCode syntax cleanly explicitly mappings independently…

Convert Binary to Hex

Convert Binary to Hex tool. Convert binary numbers to hex instantly. 100% client-side, instant,…

Convert BSON to JSON

Convert MongoDB BSON hex dumps to readable JSON in your browser. Free, offline, client-side…

Chmod Calculator

Chmod Calculator - Build Linux chmod permissions visually - read/write/execute for owner, group, public,…

Coin Flip

Free Coin Flip Online streaks, batch 10 000 flips, and optional crypto-grade RNG. Full…

Share

Embed this tool

Add this free tool to your website. Copy and paste the code: