curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_STDERR, $f = fopen(__DIR__ . "/error.log", "w+"));
    $returnHTML = curl_exec($ch);
    if ($errno = curl_errno($ch)) {
        $error_message = curl_strerror($errno);
        echo "cURL error ({$errno}):\n {$error_message}";
    }
    curl_close($ch);
    return $returnHTML;
}
// end of function grabHTML
$symbol = $_GET['symbol'];
$dataArray = array();
$yahooFinanceAPIURL = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20%20%20yahoo.finance.historicaldata%20where%20%20symbol%20%20%20%20=%20%22" . $symbol . "%22and%20%20%20%20startDate%20=%20%22" . get_date_two_weeks_ago() . "%22%20and%20%20%20%20endDate%20%20%20=%20%22" . get_todays_date() . "%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org/alltableswithkeys&callback=";
$result = grabHTML($yahooFinanceAPIURL);
$result_json = json_decode($result);
if (isset($result_json->query->results)) {
    $historicalDataArray = $result_json->query->results->quote;
    if (isset($historicalDataArray[1]->Close)) {
        $day_1_percentage = ($historicalDataArray[1]->Close - $historicalDataArray[0]->Low) / $historicalDataArray[1]->Close * 100;
        if ($day_1_percentage > 1) {
            $dataArray['day_1'] = number_format((double) $day_1_percentage, 2, '.', '');
        } else {
            $dataArray['day_1'] = "N/A";
        }
    } else {
        $dataArray['day_1'] = "N/E";
    }
    if (isset($historicalDataArray[2]->Close)) {
        $day_2_percentage = ($historicalDataArray[2]->Close - $historicalDataArray[1]->Low) / $historicalDataArray[2]->Close * 100;
Example #2
0
    				 "mwPartnerHeadLines"=>array("url"=>$mwPartnerHeadlinesLink1, "urlTitle"=>$mwPartnerHeadlinesLink1Title), 
    				 "mwPRHeadLines"=>array("url"=>$mwPRHeadlinesLink1, "urlTitle"=>$mwPRHeadlinesLink1Title), 										 
    				),JSON_UNESCAPED_SLASHES); */
    // json_encode doesn't work on my server, so I'll just manually encode the json object.
    $returnArray = '{"found":"' . $isFound . '",' . '"mwMainHeadlines":{"url":"' . $mwMainContentLink1 . '","urlTitle":"' . $mwMainContentLink1Title . '"},' . '"mwPartnerHeadLines":{"url":"' . $mwPartnerHeadlinesLink1 . '","urlTitle":"' . $mwPartnerHeadlinesLink1Title . '"},' . '"mwPRHeadLines":{"url":"' . $mwPRHeadlinesLink1 . '","urlTitle":"' . $mwPRHeadlinesLink1Title . '"}}';
    // 		fwrite($file, "right after json_encode.  array is " . $returnArray);
    echo $returnArray;
} else {
    if ($which_website == "yahoo") {
        $isFound = "";
        $ret = "";
        $url = "";
        $urlTitle = "";
        //      $url="http://$host_name/q/h?s=$symbol+Headlines";
        $url = "http://finance.yahoo.com/quote/{$symbol}";
        $result = grabHTML($host_name, $url);
        /*      $result = str_replace ('href="/', 'href="http://finance.yahoo.com/', $result);  
              $result = str_replace ('heigoldinvestments.com', 'finance.yahoo.com', $result); 
              $result = str_replace ('localhost', 'finance.yahoo.com', $result);  */
        $html = str_get_html($result);
        //      $ret = $html->find('#yfncsumtab');
        $company_name_array = $html->find('h6');
        if (preg_match('/\\"NOT_FOUND\\"\\:\\"Not Found\\"/i', $html)) {
            $isFound = "notFound";
        } else {
            $isFound = "found";
        }
        $full_company_name = $company_name_array[0];
        $full_company_name = preg_replace('/<h6.*\\">/', "", $full_company_name);
        $full_company_name = preg_replace('/<\\/h6>/', "", $full_company_name);
        $tableDataArray = $html->find('div#quote-summary div table tbody tr td');
Example #3
0
     $bigChartsHigh = $bigChartsHighLow[7];
     $bigChartsLow = $bigChartsHighLow[8];
     $bigChartsHigh = preg_replace('/<div>/', '', $bigChartsHigh);
     $bigChartsHigh = preg_replace('/<\\/div>/', '', $bigCharsHigh);
     $bigChartsHigh = (double) $bigChartsHigh;
     $bigChartsLow = preg_replace('/<div>/', '', $bigChartsLow);
     $bigChartsLow = preg_replace('/<\\/div>/', '', $bigChartsLow);
     $bigChartsLow = (double) $bigChartsLow;
     $percentageChange = number_format(100 * (($bigChartsHigh - $bigChartsLow) / $bigChartsLow), 4);
     $bigChartsHigh = number_format($bigChartsHigh, 4);
     $bigChartsLow = number_format($bigChartsLow, 4);
     $percentageChangeText = '<br><b>&nbsp; % Change</b> - \\$' . $bigChartsHigh . '/\\$' . $bigChartsLow . ' = ' . $percentageChange;
     // grab the last vix value
     //      $url = "http://bigcharts.marketwatch.com/quickchart/quickchart.asp?symb=vix&insttype=&freq=9&show=&time=1";
     $url = "http://finance.yahoo.com/quote/^VIX?p=^VIX";
     $result = grabHTML("finance.yahoo.com", $url);
     $html = str_get_html($result);
     $vixTDArray = $html->find('div#quote-header-info section span');
     $vixTDArray[0] = preg_replace('/<span.*\\">/', '', $vixTDArray[0]);
     $vixTDArray[0] = preg_replace('/<\\/span>/', '', $vixTDArray[0]);
     $vixTDReturn = "<br>Last VIX Value: " . $vixTDArray[0];
     $bigChartsReturn = preg_replace('/<\\/div>/', $vixTDReturn . '</div>', $bigChartsReturn);
     echo $bigChartsReturn;
 } else {
     if ($which_website == "etrade") {
         fwrite($file, " which_website is - " . $which_website . "\r\n");
         fwrite($file, " host_name is " . $host_name . "\r\n");
         $url = "www.etrade.wallst.com/v1/stocks/news/search_results.asp?symbol={$symbol}&rsO=new";
         // $url="http://finance.yahoo.com/q?s=$symbol&ql=1";
         $result = grabEtradeHTML("www.etrade.wallst.com", $url);
         $html = str_get_html($result);