在 php 中管理 curl 输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1234537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 01:38:51  来源:igfitidea点击:

managing curl output in php

phpcurl

提问by mrpatg

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?

问题是整个页面都喷出来了,我怎么能简单地显示“成功”或“失败”的消息?

回答by Greg

Use this option to curl_setopt():

使用此选项curl_setopt()

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

This will make curl_execreturn the data instead of outputting it.

这将使curl_exec数据返回而不是输出。

To see if it was successful you can then check $resultand also curl_error().

要查看它是否成功,您可以检查$resultcurl_error()

回答by Eric Leschinski

Also make sure to turn off this option:

还要确保关闭此选项:

curl_setopt($ch, CURLOPT_VERBOSE, 0);       

Or else it will still print everything to screen.

否则它仍然会将所有内容打印到屏幕上。