Free tool
curl to PHP
Paste a curl command and get the same request in PHP, written with PHP's cURL extension. No account; the command is only read, never run.
An example: a POST with JSON and a token
curl -X POST 'https://api.example.com/items?page=1' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-d '{"name":"pen","price":2.5}'becomes, in PHP:
PHP
<?php
$ch = curl_init('https://api.example.com/items?page=1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer YOUR_TOKEN',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"name":"pen","price":2.5}');
$body = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n", $body;
About the PHP code
The code uses the cURL extension that most PHP installations include: curl_init, then one curl_setopt per option.
Headers go into CURLOPT_HTTPHEADER as Name: value lines, the body into CURLOPT_POSTFIELDS, and CURLOPT_RETURNTRANSFER makes curl_exec return the page instead of printing it.
curl_getinfo($ch, CURLINFO_RESPONSE_CODE) is the site's status. In a real program, check curl_errno($ch) for a failed connection.
What the converter understands
The address, -X, -H, -d and its variants, --json, -u, -A, -b, -e, -G and -I, quotes and lines continued with a backslash. Options that do not change the request, such as -L, -s or --compressed, are ignored.
Other languages
curl to Python, curl to JavaScript, curl to Go, curl to Java, or all eight languages at once.
Need pages for a program, not code? gimmepage fetches any public page in one request: 1 credit a page, failed requests free.