您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

curl 怎么保留前面的 0

2024/5/10 17:47:27发布36次查看
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; } }

直接在浏览器敲返回的是 0001 用这方法返回的是1 这么保留前面的0
回复内容: 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; } }

直接在浏览器敲返回的是 0001 用这方法返回的是1 这么保留前面的0
json_decode干的好事
$content本来是0001,你json_decode($content)把它转换成数值1了。
你确定执行了curl 吗,为什么不是file_get_contents呢?
json_decode是用来对 json 格式的字符串进行编码的,那么请问,你那个是json字符串吗?是用双引号包围这的吗?
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product