$item) { $tempItem = substr($item, stripos($item, "=\"") + 2); //获取 var hq_str_sz000002="万 科A,30.780,30.800,30.510, ="之后部分 $tempItem = substr($tempItem, 0, strripos($tempItem, "\"")); //获取 万 科A,30.94,0.14,0.45,584039,178827"; ";之前部分 $tempItem = trim($tempItem); if (!empty($tempItem)) { $arr2[$index] = explode(",", $tempItem);//分割 $arr2[$index]['code'] = $codeList[$codeIndex]; $index++; } $codeIndex++; } return $arr2; } //获取指定条件的股票代码和名称列表 static private function getPartStockCodeAndNameList($exchange, $sector, $start, $end) { $url = "http://hq.sinajs.cn/list="; $data['exchange'] = $exchange; $data['sector'] = $sector; $codeList = array(); $codeIndex = 0; for($code = $start;$code < $end; $code++){ $codeStr = sprintf('%06s', $code); $url .= 's_'.$exchange.$codeStr.','; $codeList[$codeIndex] = $codeStr; $codeIndex++; } $contentList = self::curl_get_data($url, $codeList); // var_dump($contentList); foreach ($contentList as $key => $item) { $data['code'] = $item['code']; $data['name'] = trim($item[0]); if (!empty($item[0])) { //判断非法股票代码 Stock::addOrUpdateByCode($data); } } return; } //获取全部股票代码和名称列表 static public function getAllStockCodeAndNameList() { //上证主板 60**** for($i = 0; $i < 50; $i++) { $start = 600000 + $i * 200; self::getPartStockCodeAndNameList('sh', 10, $start, $start + 200); } //上证科创板 688*** for($i = 0; $i < 5; $i++) { $start = 688000 + $i * 200; self::getPartStockCodeAndNameList('sh', 11, $start, $start + 200); } //深证主板 000000~001999 for($i = 0; $i < 10; $i++) { $start = 0 + $i * 200; self::getPartStockCodeAndNameList('sz', 20, $start, $start + 200); } //深证中小板 002000~002999 for($i = 0; $i < 5; $i++) { $start = 2000 + $i * 200; self::getPartStockCodeAndNameList('sz', 21, $start, $start + 200); } //深证创业板 300*** for($i = 0; $i < 5; $i++) { $start = 300000 + $i * 200; self::getPartStockCodeAndNameList('sz', 22, $start, $start + 200); } return; } } ?>