PHP Curl Delete Request Example Code

By Hardik Savani November 5, 2023 Category : PHP

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...

Tags :
Shares