简体   繁体   English

在 php 中管理 curl 输出

[英]managing curl output in php

How do I hide the output from curl in PHP?如何在 PHP 中隐藏 curl 的输出?

My code as it stands is the following:我的代码如下:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, PSSWDINFO);
$result= curl_exec ($ch);
curl_close ($ch);

The problem is that is spews out the entire page, how can I simply show a "success" or "failed" message?问题是整个页面都喷出来了,我怎么能简单地显示“成功”或“失败”的消息?

Use this option to curl_setopt() :将此选项用于curl_setopt()

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

This will make curl_exec return the data instead of outputting it.这将使curl_exec返回数据而不是输出它。

To see if it was successful you can then check $result and also curl_error() .要查看它是否成功,您可以检查$resultcurl_error()

Also make sure to turn off this option:还要确保关闭此选项:

curl_setopt($ch, CURLOPT_VERBOSE, 0);       

Or else it will still print everything to screen.否则它仍然会将所有内容打印到屏幕上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM