/** * Returns a stock by symbol (case-insensitively) else false if not found. */ function lookup($symbol) { // reject symbols that start with ^ if (preg_match("/^\\^/", $symbol)) { return false; } // reject symbols that contain commas if (preg_match("/,/", $symbol)) { return false; } $loginpassw = 'ayush.anshul:madhepura'; $proxy_ip = '202.141.80.22'; $proxy_port = '3128'; $url = 'http://download.finance.yahoo.com/d/quotes.csv?f=snl1&s=' . $symbol; $handle = curlFile($url, $proxy_ip, $proxy_port, $loginpassw); if ($handle === false) { // trigger (big, orange) error trigger_error("Could not connect to Yahoo!", E_USER_ERROR); exit; } $array = str_getcsv($handle, ",", '"', "\\"); if ($array[2] === "N/A" || $array[2] === "0.00") { return false; } return ["symbol" => $array[0], "name" => $array[1], "price" => floatval($array[2])]; }
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port); curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP'); curl_setopt($ch, CURLOPT_PROXY, $proxy_ip); curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw); $data = curl_exec($ch); curl_close($ch); return $data; } $loginpassw = 'ayush.anshul:madhepura'; $proxy_ip = '202.141.80.22'; $proxy_port = '3128'; $url = "http://news.google.com/news?geo={$geo}&output=rss"; $contents = curlFile($url, $proxy_ip, $proxy_port, $loginpassw); if ($contents === false) { http_response_code(503); exit; } // parse RSS $rss = @simplexml_load_string($contents); if ($rss === false) { http_response_code(500); exit; } // iterate over items in channel foreach ($rss->channel->item as $item) { // add article to array $articles[] = ["link" => (string) $item->link, "title" => (string) $item->title]; }