ItSolutionStuff.com

PHP Curl Delete Request Example Code

By Hardik Savani • May 14, 2024
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...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

PHP Curl Get Request with Parameters Example

Read Now →

PHP Curl Request with Certificate (cert pem file option) Example

Read Now →

How to Upgrade PHP Version from 7.3 to 7.4 in Ubuntu?

Read Now →

PHP Remove Directory and Files in Directory Example

Read Now →

Angular Http Post Request Example

Read Now →

Codeigniter Curl Post Request with Parameters Example

Read Now →

PHP CURL Post Request with Parameters Example

Read Now →

Laravel CURL Request Example using Ixudra/curl

Read Now →

How to Convert Object into Array in PHP?

Read Now →

PHP Download File from URL using CURL Request Example

Read Now →

How to Generate Random Alphanumeric String in PHP?

Read Now →