Silence output curl_setopt_array

272 views Asked by At

For sending a user a Boxcar notification, I use this example:

curl_setopt_array(
    $chpush = curl_init(),
    array(
        CURLOPT_URL => "https://new.boxcar.io/api/notifications",
        CURLOPT_POSTFIELDS => array(
            "user_credentials" => 'ACCESS_TOKEN',
            "notification[title]" => 'message title',
            "notification[long_message]" => '<b>Some text or HTML for the full layout page notification</b>',
            "notification[sound]" => "bird-1",
        )));
$ret = curl_exec($chpush);
curl_close($chpush);

But I get some output on my page, which is probably the response of the Boxcar server. How can I prevent that output from being printed?

1

There are 1 answers

0
B_s On

I already found the solution:

Set CURLOPT_RETURNTRANSFER to TRUE. See this StackOverflow Answer for more information. For future reference, to send the user a Boxcar notification, you could also use:

$chpush = curl_init();
$boxcarData = array(
        "user_credentials" => 'ACCESS_TOKEN',
        "notification[title]" => 'message title',
        "notification[long_message]" => '<b>Some text or HTML for the full layout page notification</b>',
        "notification[sound]" => "bird-1",
);
curl_setopt($chpush, CURLOPT_URL, "https://new.boxcar.io/api/notifications");
curl_setopt($chpush, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($chpush, CURLOPT_POSTFIELDS, $boxcarData);
$ret = curl_exec($chpush);
curl_close($chpush);