cURL to PHP
Convert a curl command to PHP cURL
About cURL to PHP
Builds PHP code on the built-in cURL extension, with every option set in one curl_setopt_array call. -H headers fill CURLOPT_HTTPHEADER, -u maps to CURLOPT_USERPWD, -L to CURLOPT_FOLLOWLOCATION, and JSON bodies are rebuilt as a PHP array inside json_encode(). No Composer packages are required, and the conversion happens entirely in your browser.
Category: API.
Frequently asked questions
Does the PHP code use Guzzle or the cURL extension?
▾
It uses PHP's built-in cURL extension (ext-curl): curl_init, one curl_setopt_array call, curl_exec and curl_close, with no Composer packages. The extension must be enabled in your PHP installation, and the response is decoded with json_decode($response, true) and shown with print_r.
Which curl_setopt options do the cURL flags become?
▾
Any method other than GET is set with CURLOPT_CUSTOMREQUEST, -H headers go into CURLOPT_HTTPHEADER, -u into CURLOPT_USERPWD and -L into CURLOPT_FOLLOWLOCATION. -k only sets CURLOPT_SSL_VERIFYPEER to false, so host name checking through CURLOPT_SSL_VERIFYHOST stays on.
Is -F sent as multipart/form-data in the PHP output?
▾
Yes. -F fields are passed to CURLOPT_POSTFIELDS as a PHP array, and libcurl sends an array as multipart/form-data. A value such as @photo.jpg is sent as plain text, because PHP 7 and later require a CURLFile object to upload a file.
What happens to -b, -A, --compressed and --max-time in PHP?
▾
They are not converted. Add CURLOPT_COOKIE for -b, CURLOPT_USERAGENT for -A, CURLOPT_ENCODING set to an empty string for --compressed and CURLOPT_TIMEOUT for --max-time to the options array if you need them.