• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

curl 怎么保留前面的 0

php 搞代码 3年前 (2022-01-25) 19次浏览 已收录 0个评论
文章目录[隐藏]
<code> private function _sendRequest($url)    {        $content = "";        if(function_exists('file_get_contents'))        {            $content = @file_get_contents($url);        }        else        {            $ch = curl_init();            curl_setopt($ch, CURLOPT_URL, $url);            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //allow redirects            curl_setopt($ch, CURLOPT_HEADER, false);            $content = curl_exec($ch);            $error = curl_errno($ch);            $info = curl_getinfo($ch);            curl_close($ch);        }        $contenArr = json_decode($content);        if(json_last_error() === JSON_ERROR_NONE)        {            return $contenArr;        }        else        {            return $content;        }    } </code>

直接在浏览器敲返回的是 0001 用这方法返回的是1 这么保留前面的0

本2文来*源gao($daima.com搞@代@#码(网搞gaodaima代码

回复内容:

<code> private function _sendRequest($url)    {        $content = "";        if(function_exists('file_get_contents'))        {            $content = @file_get_contents($url);        }        else        {            $ch = curl_init();            curl_setopt($ch, CURLOPT_URL, $url);            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //allow redirects            curl_setopt($ch, CURLOPT_HEADER, false);            $content = curl_exec($ch);            $error = curl_errno($ch);            $info = curl_getinfo($ch);            curl_close($ch);        }        $contenArr = json_decode($content);        if(json_last_error() === JSON_ERROR_NONE)        {            return $contenArr;        }        else        {            return $content;        }    } </code>

直接在浏览器敲返回的是 0001 用这方法返回的是1 这么保留前面的0

json_decode干的好事
$content本来是0001,你json_decode($content)把它转换成数值1了。

你确定执行了curl 吗,为什么不是file_get_contents呢?
json_decode是用来对 JSON 格式的字符串进行编码的,那么请问,你那个是json字符串吗?是用双引号包围这的吗?


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:curl 怎么保留前面的 0
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址