PHP新型冠状病毒API接口代码
PHP新型冠状病毒API接口代码
<?php $a = file_get_contents("https://3g.dxy.cn/newh5/view/pneumonia"); $b = getSubstr($a,'window.getTimelineService = ','}catch(e){}');//实时热点 $c = getSubstr($a,'window.getAreaStat = ','}catch(e){}');//国内 $d = getSubstr($a,'window.getListByCountryTypeService2 = ','}catch(e){}');//国外 $e = getSubstr($a,'window.getStatisticsService = ','}catch(e){}');//统计 $f = json_decode($e, true); echo '{"data": ['.'{"result": '.$b.'},'.'{"China": '.$c.'},'.'{"abroad": '.$d.'},'.$e.']}'; function getSubstr($str, $leftStr, $rightStr){ $left = strpos($str, $leftStr); $right = strpos($str, $rightStr,$left); if($left < 0 or $right < $left) return ''; return substr($str, $left + strlen($leftStr), $right-$left-strlen($leftStr)); } ?>
本文结束