Http://www.51boxue.net/phper/php-cy/95985.htm
Stock information query function we need to crawl the data of the third party, and then we analyze the data to compose what we want, let's look at a PHP stock information query class.
Git Hub Address:GitHub.com/widuu/stock
Exception($result [' errmsg '], 1); Return } return $result [' Retdata ']; }/** * Enter pinyin or kanji to get stock code * @param name String * @return Stockid String */private static function Getstockid ($name) {$result = Self::httpget (Self::socket_suggest.urlencode (iconv (' utf-8 ', ' GBK ', $name)), false); if (empty ($result)) {throw newException("Stock name NOT EXISTS", 2); Return } $stockid = $result [' Result '][0][' code ']; $stock = Explode ('. ', $stockid); return $stock [1]. $stock [0]; }/** * Get Get method * @param param string parameter * @author Widuu */private static function HttpGet ($url, $ Header=false) {$curlHandle = Curl_init (); curl_setopt ($curlHandle, Curlopt_url, $url); if ($header) {curl_setopt ($curlHandle, Curlopt_httpheader, Array (' Apikey: '. Self:: $apikey)); } curl_setopt ($curlHandle, Curlopt_returntransfer, 1); curl_setopt ($curlHandle, Curlopt_ssl_verifypeer, false); curl_setopt ($curlHandle, Curlopt_ssl_verifyhost, false); curl_setopt ($curlHandle, Curlopt_timeout, 10); $content = curl_exec ($curlHandle); Curl_close ($curlHandle); Return $header? Json_decode ($content, True): Json_decode (Iconv (' GBK ', ' utf-8 ', trim ($content)), true); }}//Test Code Stock::getinstance ("5040BCBFEBB0A4CFFC7BE278723255AA");p Rint_r (Stock::getsinglestock (' sh601000 ')); Echo stock::getkline (' Zijin mining ') );? >
The above describes the PHP stock information query class, including the exception,git,github aspects of the content, I hope that the PHP tutorial interested in a friend helpful.