user1452893
user1452893

Reputation: 868

How to suppress curl JSON response

Here is the code which in a file from the browser:

<?php
curl_setopt_array($ch = curl_init(), array(
  CURLOPT_URL => "https://somesite/messages.json",
  CURLOPT_POSTFIELDS => array(
  "token" => "xxx",
  "user" => "xxx",
  "message" => "hello world",
)));
curl_exec($ch);
curl_close($ch);
?>

This runs properly and returns this to the browser:

{"status":1,"request":"34bb823184583c8bca6d9d56d297d795"}

I want to suppress that message and replace it with something else like a text string such as "worked". \

Displaying an image or pointing to a success .html page would be nice.

This is my first use of curl.

Upvotes: 0

Views: 267

Answers (1)

iMx
iMx

Reputation: 846

set CURLOPT_RETURNTRANSFER to true and let curl_exec($ch) return a value in a variable

<?php
curl_setopt_array($ch = curl_init(), array(
  CURLOPT_URL => "https://somesite/messages.json",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POSTFIELDS => array(
  "token" => "xxx",
  "user" => "xxx",
  "message" => "hello world",
)));
$result = curl_exec($ch);
curl_close($ch);
echo "some text"; // or echo file_get_content('some_html_page.html');
?>

Upvotes: 1

Related Questions