Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ricardogolez's avatar

how to convert curl to curl php OR run this on a shell plugin command

does anyone know how to convert this curl to curl php?

NOTE this is running normally on the terminal.

curl -d
'{
    "color":"rainbow",
    "message":"NEED HELP",
    "notify":false,
    "message_format":"text"
}'
-H 'Content-Type: application/json' https://url.com

^ NOTE its NOT enclosed in a ""

OR does anyone know why I'm getting this error when I'm trying to run it on a Shell Plugin Commands

"curl -d
'{
    "color":"rainbow",
    "message":"NEED HELP",
    "notify":false,
    "message_format":"text"
}'
-H 'Content-Type: application/json' https://url.com"

^ NOTE its enclosed in a "" the error is "Unexpected characters near ......"

the reason I'm converting this to CURL PHP cause it won't run on the Shell Plugin Command

0 likes
1 reply
Braunson's avatar

@Ricardogolez I'm not sure what Shell Plugin Command you mean but..

If your going to regularly use this, I'd suggest a Laravel CURL package for easier readability, like this https://github.com/ixudra/curl

Otherwise, learning to CURL in PHP http://www.hackingwithphp.com/15/10/2/your-first-curl-scripts

Assuming your POSTing to the URL, it'll be something like this.. (untested)

$data = [
    'color' =>  'rainbow',
    'message' => 'NEED HELP',
    'notify' => false,
    'message_format' => 'text'
];

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

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://url.com");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$results = curl_exec($ch);
curl_close($ch);

echo $results;
1 like

Please or to participate in this conversation.