代码如下
$stocklist="sh000001,int_hangseng,int_sp500,fx_susdcnh,hf_XAU";
$stock_str= file_get_contents("http://hq.sinajs.cn/list=".$stocklist);
preg_match_all("/(?:\=)(.*)(?:\;)/i",$stock_str,$arrayA);
preg_match_all("/\d*\.\d*/",$arrayA[1][0],$array0);
preg_match_all("/\d*\.\d*/",$arrayA[1][1],$array1);
preg_match_all("/\d*\.\d*/",$arrayA[1][2],$array2);
preg_match_all("/\d*\.\d*/",$arrayA[1][3],$array3);
preg_match_all("/\d*\.\d*/",$arrayA[1][4],$array4);
$sh000001=round($array0[0][2],2);
$int_hangseng=round($array1[0][0],2);
$int_sp500=round($array2[0][0],2);
$fx_susdcnh=round($array3[0][0],4);
$hf_XAU=round($array4[0][0],2);
备注:sh000001是上证指数,int_hangseng是恒生指数,int_sp500是标普500指数,fx_susdcnh是美元/离岸人民币汇率(香港),hf_XAU是伦敦金/美元价格(现货黄金),hf_GC是COMEX黄金/美元价格(国际黄金期货)