要获取数组中的任何值,请以与 file_id 相同的方式引用它,但将键替换为您之后的值,例如:
$api['file_id'];
$api['file_name'];
$api['file_type'];
$api['file_size'];
然后要简单地在页面上显示它,您可以使用 echo:
echo $api['file_id'];
echo $api['file_name'];
echo $api['file_type'];
echo $api['file_size'];
所以你的完整代码是:
<?php
$api_key = "Uez4TWYH6OAQQHoUcICWJ8UUFYmwQ";
$file_id = "LNzcOp2b1352047884";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,'http://ads.ngsms.tk/api/info.php?api_key='.$api_key.'&file_id='.$file_id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$api = curl_exec($ch);
//print_r($api);
$fileid = get_string_between($api, "[file_id] => ", "[file_name] ");
$filename = get_string_between($api, " [file_name] => ", " [file_type] => ");
$filetype = get_string_between($api, " [file_type] => ", " [file_size] =>");
$filesize = get_string_between($api, " [file_size] => ", ")");
echo "ID: $fileid <br /> name: $filename <br />type: $filetype <br /> size: " .$filesize;
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}