Convert a curl command to PHP cURL code instantly in your browser. The command stays on your device.
curl to PHP Converter
Convert a curl command to PHP cURL code instantly in your browser. The command stays on your device.
Your curl command is converted to PHP locally in your browser and never uploaded, but avoid pasting real production tokens or credentials into any tool.
This curl to php converter turns a curl command into a PHP script that uses the built-in cURL extension, the same client most PHP developers already reach for when calling an API. It reads flags like -X, -H, -d, --data-raw, --json, -u, -b, and -G and emits a curl_init() handle configured through a single curl_setopt_array() call, with CURLOPT_HTTPHEADER for your headers and CURLOPT_POSTFIELDS for the body. The result returns the response via CURLOPT_RETURNTRANSFER and prints the HTTP status code, so it slots into a controller, a script, or a quick test. Use it to move a terminal curl request into PHP without remembering each CURLOPT_ constant. The conversion runs in your browser, so the command and any tokens in it are processed locally on your device and never uploaded.
Features
Emits a curl_init() handle configured with a single curl_setopt_array() call
Sets CURLOPT_CUSTOMREQUEST to the method inferred from the curl flags
Maps -H/--header flags into a CURLOPT_HTTPHEADER array of Name: Value strings
Sends the request body through CURLOPT_POSTFIELDS
Turns -u/--user into a Basic auth header and handles cookies, user-agent, and referer
Appends -G/--get data to the URL as a query string
Returns the body with CURLOPT_RETURNTRANSFER and reads the status with curl_getinfo
Copy the result or download it as request.php with one click
How to use the cURL to PHP
Paste your curl command into the cURL command box.
Read the generated PHP cURL script in the output panel.
Check the warning banner for any flags that were adjusted or skipped.
Headers become a CURLOPT_HTTPHEADER array and the body goes into CURLOPT_POSTFIELDS.
Common errors & troubleshooting
Call to undefined function curl_init(). — The PHP cURL extension is not enabled. Install or enable ext-curl (for example php-curl on Debian/Ubuntu) and restart PHP.
curl_exec returns false instead of a response. — An error occurred on the handle. Add curl_error($ch) before curl_close to see why, and check the URL, TLS, and headers.
Headers in CURLOPT_HTTPHEADER are ignored by the server. — Each entry must be a single "Name: Value" string. The converter formats them that way; keep the colon and space if you edit them.
Frequently asked questions
How do I convert a curl command to PHP?
Paste the curl command into the input box and the converter renders a PHP cURL script on the right that you can copy or download as request.php.
Does the output use the PHP cURL extension or Guzzle?
It uses the native PHP cURL extension (curl_init, curl_setopt_array, curl_exec), so there is no Composer dependency to install.
How are request headers represented in the PHP code?
Each -H header becomes a single "Name: Value" string inside the CURLOPT_HTTPHEADER array that curl_setopt_array passes to the handle.
Where does the request body go in the generated PHP?
The body is assigned to CURLOPT_POSTFIELDS, and CURLOPT_CUSTOMREQUEST carries the HTTP method so it works for POST, PUT, PATCH, and DELETE.
Is my curl command uploaded when I convert it to PHP?
No. The curl to php conversion runs entirely in your browser, so the command and any credentials in it stay on your device.
Related tools
cURL to Python — Convert a curl command to Python requests code.
cURL to Go — Convert a curl command to Go net/http code.