ItSolutionStuff.com

PHP Curl PUT Request Example Code

By Hardik Savani • May 14, 2024
PHP

In this example, you will learn php curl put request example. I’m going to show you about put method in curl php. you'll learn php curl put request with body. i explained simply step by step how to call put request with data using php curl.

i will give you two very simple example here, one simple put request with php curl. so let's see bellow examples:

PHP Curl PUT Request:

<?php

$url = "https://reqres.in/api/users/2";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

$updateArray = ['name' => 'Hardik', 'email' => 'hardik@gmail.com'];

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($updateArray));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$headers = [];

$headers[] = 'Content-Type:application/json';

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 POST Request with Headers Example

Read Now →
ā˜…

PHP Curl Get Request with Parameters Example

Read Now →
ā˜…

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

Read Now →
ā˜…

PHP Change File Name in Folder Example

Read Now →
ā˜…

PHP Copy File from One Folder to Another Example

Read Now →
ā˜…

PHP Laravel Left Join Query 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 →
ā˜…

PHP Download File from URL using CURL Request Example

Read Now →
ā˜…

How to access PHP variables in JQuery?

Read Now →