[{"data":1,"prerenderedAt":67},["Reactive",2],{"/samples/php/curl":3,"related:5fHgZ9iR1B":61},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":11,"link":12,"body":13,"_type":56,"_id":57,"_source":58,"_file":59,"_extension":60},"/samples/php/curl","php",false,"","Curl","cURL is commonly used as an extension to make HTTP requests and handle responses from within PHP scripts. It provides a wide range of features and options for making HTTP requests, including support for various protocols and authentication methods.","PHP","curl","https://www.php.net/manual/en/book.curl.php",{"type":14,"children":15,"toc":53},"root",[16,32,44],{"type":17,"tag":18,"props":19,"children":20},"element","p",{},[21,30],{"type":17,"tag":22,"props":23,"children":26},"a",{"href":12,"rel":24},[25],"nofollow",[27],{"type":28,"value":29},"text","cURL",{"type":28,"value":31}," is commonly used as an extension to make HTTP requests and handle responses from within PHP scripts. It provides a wide range of features and options for making HTTP requests, including support for various protocols and authentication methods.",{"type":17,"tag":33,"props":34,"children":38},"pre",{"className":35,"code":37,"language":5,"meta":7},[36],"language-php","\u003C?php\n\nfunction convert($api_key, $params, $endpoint = 'pdf') {\n    // Ensure the endpoint is valid\n    if (!in_array($endpoint, array('pdf', 'png', 'jpg', 'webp'))) {\n        throw new Exception('Invalid endpoint specified');\n    }\n\n    // Set the API URL\n    $url = 'https://api.pdfshift.io/v3/convert/' . $endpoint;\n\n    // Set cURL options\n    $curl = curl_init($url);\n    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);\n    curl_setopt($curl, CURLOPT_POST, true);\n    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));\n    curl_setopt($curl, CURLOPT_HTTPHEADER, array(\n        'Content-Type: application/json',\n        'X-API-Key: '.$api_key\n    ));\n\n    // Execute the cURL request\n    $response = curl_exec($curl);\n\n    // Check for cURL errors\n    if ($response === false) {\n        $error_message = curl_error($curl);\n        curl_close($curl);\n        throw new Exception(\"cURL error: $error_message\");\n    }\n\n    // Get the HTTP status code\n    $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n\n    // Close cURL resource\n    curl_close($curl);\n\n    // Check if the request was successful\n    if ($http_status !== 200) {\n        throw new Exception(\"Request failed with HTTP status code: $http_status\");\n    }\n\n    // Check if filename or webhook were passed\n    if (array_key_exists('filename', $params) || array_key_exists('webhook', $params)) {\n        // Decode the response JSON\n        return json_decode($response, true);\n    }\n\n    // Return the binary content\n    return $response;\n}\n",[39],{"type":17,"tag":40,"props":41,"children":42},"code",{"__ignoreMap":7},[43],{"type":28,"value":37},{"type":17,"tag":33,"props":45,"children":48},{"className":46,"code":47,"language":5,"meta":7},[36],"try {\n    $result = convert('sk_XXXXXXXXXXXXXX', array(\n        'source' => 'https://en.wikipedia.org/wiki/REST'\n    ));\n\n    var_dump($result);\n} catch (Exception $e) {\n    echo 'Error: ' . $e->getMessage();\n}\n",[49],{"type":17,"tag":40,"props":50,"children":51},{"__ignoreMap":7},[52],{"type":28,"value":47},{"title":7,"searchDepth":54,"depth":54,"links":55},2,[],"markdown","content:samples:php:curl.md","content","samples/php/curl.md","md",[62,63],{"_path":4,"language":10,"library":11,"_id":57},{"_path":64,"language":10,"library":65,"_id":66},"/samples/php/guzzle","guzzle","content:samples:php:guzzle.md",1785426823420]