cURL to PHP Converter
CV-96Paste a curl command, for example one copied from API docs or browser dev tools, and get PHP code that makes the same request with the cURL extension.
Runs in your browser. Nothing is uploaded.
curl command (bash style quoting)
PHP
How to use it
- Paste the curl command. Line breaks with a backslash at the end are fine.
- Click Convert to PHP.
- Read any comment at the top that lists options that were not converted.
- Copy the code into your script, replace placeholders such as tokens, and test it.
What is converted
The tool reads bash style quoting, including $'...' strings and line continuations, and writes a curl_setopt_array call. It converts the URL, -X, -H, -d and the --data variants, --data-urlencode, --json, -F form fields and file uploads (as CURLFile), -u, -A, -e, -b, -G, -L, -k, -I, -i, --compressed, -x, and the timeout options. A body given with -d makes the request a POST unless you set another method with -X.
What is not converted
Any option the tool does not know is listed in a comment at the top rather than ignored quietly. Options that read from a file, such as -d @body.json, are refused because the file is not available here; paste the content with --data-raw instead. Windows cmd quoting, pipes, redirects and shell variables are not interpreted. -k turns off certificate checks in the PHP code, which you should not leave on in production. The PHP is not run.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
No address found. Add the URL, for example https://api.example.com/items. | The command has options but no URL. | Add the address to the command. |
A single quote is never closed. | The command has an opening ' without a closing one. | Close the quote, or check for a ' inside a single quoted string. |
Questions people ask
How do I convert a curl command to PHP?
Paste the command here and click Convert to PHP. You get a script that calls curl_init and curl_setopt_array with the matching options, then runs curl_exec.
How do I send JSON with PHP cURL?
Set CURLOPT_POSTFIELDS to the JSON string and add a Content-Type: application/json header in CURLOPT_HTTPHEADER. The converter does this from a curl command that has --data-raw and a header.
What does -L do in PHP?
It becomes CURLOPT_FOLLOWLOCATION => true, which makes PHP follow redirects. --max-redirs becomes CURLOPT_MAXREDIRS. It becomes CURLOPT_FOLLOWLOCATION => true, which makes PHP follow redirects the way curl does. The --max-redirs option becomes CURLOPT_MAXREDIRS, and without -L PHP does not follow redirects.
How is basic auth written in PHP cURL?
curl -u user:pass becomes CURLOPT_USERPWD => 'user:pass'. Keep real credentials out of source files and load them from the environment. A user name with no colon is written with an empty password.
Why was my -d @file refused?
The command asks curl to read the body from a file on your computer. The tool cannot read it, so paste the file content and use --data-raw.
Can it convert a command copied from Chrome?
Yes for the bash version of Copy as cURL. The Windows cmd version uses different quoting and is not supported. Choose the cURL (bash) option in the Network panel, not cURL (cmd).
About this tool
Reads a curl command written with bash quoting (single quotes, double quotes, $'...' strings, backslash line breaks) and writes PHP that sets the same options with curl_setopt_array. It covers the URL, -X, -H, -d and its --data variants, --data-urlencode, --json, -F form fields and file uploads, -u, -A, -e, -b, -G, -L, -k, -I, -i, --compressed, -x and the two timeout options. Any option it does not convert is listed in a comment instead of being dropped silently. Options that read a file (such as -d @file) are refused. Windows cmd quoting, pipes, redirects and shell variables are not interpreted. The PHP is not run, so check it against the API before use.