gpt4 book ai didi

php - curl_exec 在我不想时打印结果

转载 作者:IT老高 更新时间:2023-10-28 11:58:51 25 4
gpt4 key购买 nike

我正在使用以下代码:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_TIMEOUT, 12);

$result = curl_exec($ch);

curl_close ($ch);

但是它会立即打印结果。是否可以将 JSON 结果放入变量中,以便我可以在需要时打印出来?

最佳答案

设置CURLOPT_RETURNTRANSFER选项:

// ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$result = curl_exec($ch);

根据 the docs :

CURLOPT_RETURNTRANSFER - TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.

关于php - curl_exec 在我不想时打印结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4803948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com