cURL to PHP
Paste any curl command and get ready-to-run PHP code — cURL extension, Guzzle, or file_get_contents.
About cURL to PHP Converter
This tool converts any curl command into equivalent
PHP code. It supports three popular output styles: the native PHP cURL extension (curl_setopt), the Guzzle HTTP client used across
Laravel and Symfony projects, and plain file_get_contents with a stream context for
quick scripts without extra dependencies.
Everything runs 100% in your browser — your commands, tokens, and API keys never leave your device. Parsing handles multi-line commands with backslash continuation, single and double quotes, headers, JSON bodies, form fields, basic auth, cookies, user-agent, referer, TLS options, and more.
How to Use
- Paste your curl command on the left (works with multi-line commands using
\continuations), or click Load Sample to try it out. - Pick your output style: PHP cURL extension, Guzzle, or
file_get_contents. - View the PHP code on the right — it updates as you type or change options.
- Copy the result with the Copy button and paste it into your PHP project. Add your real credentials/tokens before running.
Supported curl Flags
Request
-X / --request— HTTP method-H / --header— request headers-d / --data / --data-raw— body-F / --form— multipart form-G / --get— force GET-I / --head— HEAD request
Options
-u / --user— basic auth-A / --user-agent-e / --referer-b / --cookie-L / --location— follow redirects-k / --insecure— skip TLS verify--compressed
Common Use Cases
- API integration: Drop in a curl example from API docs (Stripe, OpenAI, GitHub, Twilio) and get working PHP code instantly.
- Laravel / Symfony projects: Convert curl snippets to Guzzle calls that fit the conventions of modern PHP frameworks.
- WordPress development: Turn third-party API curl examples into PHP code for plugins, themes, and REST endpoints.
- Learning PHP HTTP: See how the same request maps to cURL, Guzzle, and file_get_contents side by side.
- Debugging: Reproduce a curl command from your terminal inside a PHP application to isolate request/response issues.
Frequently Asked Questions
Which PHP output style should I pick?
Use PHP cURL for maximum control and zero extra dependencies — it ships with PHP and handles any request. Use Guzzle if you already use it (Laravel, Symfony, most modern PHP apps) — the code is cleaner and testable. Use file_get_contents for very simple GET/POST requests when you can't install extensions or composer packages.
Does this tool handle multi-line curl commands?
Yes. Backslash + newline continuations (\ at the
end of a line) are joined before parsing, so you can paste curl commands exactly as they
appear in documentation without manually flattening them.
Are JSON request bodies handled correctly?
Yes. The -d value is passed through as a string,
preserving your JSON exactly. If the body looks like JSON and you chose Guzzle, the code
still sets it via body — swap to Guzzle's json option if you want automatic encoding.
Is multipart form data (-F) supported?
Yes. -F key=value pairs are converted to a PHP
array passed to CURLOPT_POSTFIELDS (which makes PHP
send multipart). For Guzzle, they go into the multipart option. For file uploads (-F file=@path), replace the
generated value with a CURLFile instance.
How is basic auth (-u user:pass) converted?
For the PHP cURL extension, the value is passed to CURLOPT_USERPWD.
For Guzzle, the user and password are split into the auth option. For file_get_contents, a base64-encoded Authorization:
Basic header is added to the stream context.
Is my curl command sent to a server?
No. Parsing and code generation run entirely in your browser using JavaScript. Your curl commands — including any API tokens, bearer tokens, or cookies — never leave your device, so it's safe to use with production credentials.
What PHP version is the output compatible with?
The generated code uses short array syntax [] (PHP 5.4+) and standard functions. The PHP cURL extension output works on any host with the curl extension enabled. Guzzle output is compatible
with Guzzle 7 (PHP 7.2+).
Should I use -k / --insecure in production?
No. -k disables TLS certificate verification
and exposes you to man-in-the-middle attacks. The converter honors the flag if present for
parity with your curl command, but remove the CURLOPT_SSL_VERIFYPEER
= false line before shipping the code to production.
Can I chain requests or handle cookies across calls?
The generated snippet is a single request. For cookie persistence across multiple requests,
add CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE (PHP cURL), or reuse a Guzzle CookieJar instance across $client->request(...) calls.