<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.xxx.com/api/pool_stats?pool_type=xxx,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' xxxxxxxxxxxxxxxxxxx
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
打开返回数据如下
[{"country_code":"ad","country_name":"Andorra","count":102},{"country_code":"ae","country_name":"United Arab Emirates","count":539},{"country_code":"af","country_name":"Afghanistan","count":1},{"country_code":"al","country_name":"Albania","count":431},{"country_code":"am","country_name":"Armenia","count":41},{"country_code":"aq","country_name":"Antarctica","count":1},{"country_code":"ar","country_name":"Argentina","count":411},{"country_code":"at","country_name":"Austria","count":1145},{"country_code":"au","country_name":"Australia","count":7753},{"country_code":"ba","country_name":"Bosnia and Herzegovina","count":55}]
需要修改为一行一个
国家2位代码: "ad " 国家全称:"Andorra" 目前数量:102
国家2位代码: "ae " 国家全称:"United Arab Emirates" 目前数量:539
国家2位代码: "af " 国家全称:"Afghanistan" 目前数量:1
echo $response; 这里怎么写才能达到以上效果
第二个问题
同样的打开PHP返回数据如下
{"id":329859,"label":"datacenter1","login":"xxxxx","password":"xxxxxx","balance":5368033729,"balance_format":"5 GB","threads":400,"sticky_range":{"start":10000,"end":30000},"allowed_ips":["125.1.1.1","60.249.20.180"],"blocked":false,"pool_type":"datacenter","default_pool_parameters":{"countries":["us","it","jp","de"],"cities":[""],"states":[""],"zipcodes":[],"asns":["7922"],"exclude_countries":[],"exclude_asn":[],"anonymous_filter":false,"rotation_interval":10},"blocked_hosts":[]}
需要只保留 allowed_ips":["125.1.1.1","60.249.20.180"]得到以下格式
allowed_ips:
125.1.1.1
60.249.20.180
echo $response; 这里怎么写才能达到以上效果