CURLOPT_RETURNTRANSFER在不需要时输出结果 [英] CURLOPT_RETURNTRANSFER outputting the results when not needed

查看:51
本文介绍了CURLOPT_RETURNTRANSFER在不需要时输出结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

                            $ch = curl_init();

                            // set URL and other appropriate options
                            curl_setopt($ch, CURLOPT_URL, $url);
                            curl_setopt($ch, CURLOPT_TIMEOUT, 12); 
                            curl_setopt($ch, CURLOPT_HEADER, 0);
                            //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

                            // grab URL and pass it to the browser
                            curl_exec($ch);

                            $res = curl_exec($ch);
                            var_dump($res);

                            // close cURL resource, and free up system resources
                            curl_close($ch);
                            echo "<br />\n";
                            echo "<br />\n";
                            $resArr = json_decode($res, 1); // decodes the json string to an array
                            echo $resArr['id'] // outputs the id from your json result

我不希望将JSON代码显示在网页上,而是希望将其存储在变量中,以便在需要时可以将其打印出来.

I do not want the JSON code to be displayed on the webpage, but rather to be stored in a variable so I can print it out when I want to.

我已阅读到CURLOPT_RETURNTRANSFER应该可以工作,但是结果仍以JSON格式显示.有人可以建议解决方案吗?

I have read that CURLOPT_RETURNTRANSFER should work, however the results are still being displayed in JSON format. Could anyone advise of a solution?

推荐答案

只需删除或注释 var_dump($ res); ,因为这将以 $ res 并通过删除它不会显示您从CURL接收到的json数据.希望对您有帮助.

just remove or comment the var_dump($res); since this is print the data in $res and by removing it will not diplay the json data that you are receving from CURL. Hope this might help you.

这篇关于CURLOPT_RETURNTRANSFER在不需要时输出结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆