PHP Curl Delete Request Example Code
In this tutorial, i will show you php curl delete request example. we will help you to give example of delete method in curl php. this example will help you php curl delete request. you can understand a concept of how to call delete request using php curl.
i will give you two very simple example here, one simple delete request with php curl and another will delete request with header. so let's see bellow examples:
PHP Curl Delete Request:
<?php
$url = "https://api.mywebtuts.com/api/users/2";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$result = json_decode($result);
curl_close($ch);
print_r($result);
?>
PHP Curl Delete Request with Headers:
<?php
$url = "https://api.mywebtuts.com/api/users/2";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [];
$headers[] = 'Content-Type:application/json';
$token = "your_token";
$headers[] = "Authorization: Bearer ".$token;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$result = json_decode($result);
curl_close($ch);
print_r($result);
?>
i hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- PHP Curl Get Request with Parameters Example
- PHP Curl Request with Certificate (cert pem file option) Example
- How to Upgrade PHP Version from 7.3 to 7.4 in Ubuntu?
- PHP Remove Directory and Files in Directory Example
- Angular Http Post Request Example
- Codeigniter Curl Post Request with Parameters Example
- PHP CURL Post Request with Parameters Example
- Laravel CURL Request Example using Ixudra/curl
- How to Convert Object into Array in PHP?
- PHP Download File from URL using CURL Request Example
- How to Generate Random Alphanumeric String in PHP?