PHP文件\u获取\u内容错误

PHP文件\u获取\u内容错误,php,html,web-services,finance,stockquotes,Php,Html,Web Services,Finance,Stockquotes,我正在建立一个股票分析网站,以使用股票信息,如价格历史等。一旦我获得数据,我将实施我自己的一些算法,但我在获取历史数据方面遇到了困难。该网站托管在biz.nf的免费网站上。包含的connect.php文件包含所有需要的sql信息,并连接到数据库。我有错误检查,所以我知道这不是问题所在。我还尝试手动复制/粘贴链接,它们可以正常工作,因此我可以正确创建URL。我在这个网站和其他网站上遇到了一些类似的话题,但我没有看到一个明确的解决方案如何修复它,也没有看到它发生的明确原因。雅虎阻止了我吗? 另外,我

我正在建立一个股票分析网站,以使用股票信息,如价格历史等。一旦我获得数据,我将实施我自己的一些算法,但我在获取历史数据方面遇到了困难。该网站托管在biz.nf的免费网站上。包含的connect.php文件包含所有需要的sql信息,并连接到数据库。我有错误检查,所以我知道这不是问题所在。我还尝试手动复制/粘贴链接,它们可以正常工作,因此我可以正确创建URL。我在这个网站和其他网站上遇到了一些类似的话题,但我没有看到一个明确的解决方案如何修复它,也没有看到它发生的明确原因。雅虎阻止了我吗? 另外,我想说的是,我对PHP编程很陌生,但是我有一个C和C++的背景,所以如果你能提供帮助,请考虑这个问题。 提前谢谢

下面是我执行的index.php文件的代码

代码:

我用粗体(每边两个星号)在发生错误的地方写下了文本

此外,im托管网站的服务器具有allow_url_fopen=1 如果是这样的话,yahoo.com会阻止我,有没有办法?
是否有其他方法获取所有历史股票数据?

您确定您的共享主机允许连接到远程url吗?不太可能

大多数共享主机往往不会在php.ini中将allow_url_fopen设置为true


也许可以改用curl

您在服务器上的权限设置是否正确?它拒绝连接,所以有点不对劲。就像我说的,我对所有这些网络编程都很陌生,所以我不确定你的确切意思。我理解权限的概念,但你能详细说明一下吗?也许可以举个例子,说明什么可能是错的,什么是我有错的许可。
<html>
  <head>
    <title>StockGrader</title>
  </head>
    <body bgcolor="green"  text="black" link="red">
      <div id="header">
          <hr>
             <h1>Welcome To <b><i>StockGrader</b></i><h1/></hr>

<?php
  include("phpINCLUDES/connect.php");

//function that creates a url from which to download data
  function createURL($ticker) 
  {       $currentMonth = date("n") - 1; //"n" current month as a 1-digit number
          $currentDay = date("j");       //"j" current day as a 1-digit number
          $currentYear = date("Y");      //"Y" current year as a 4-digit number
          echo "current URL is http://ichart.finance.yahoo.com/table.csv?s=$ticker&d=$currentMonth&e=$currentDay&f=$currentYear&g=d&a=3&b=10&c=2013&ignore=.csv";
          echo "\n\n\n";
          return "http://ichart.finance.yahoo.com/table.csv?s=$ticker&d=$currentMonth&e=$currentDay&f=$currentYear&g=d&a=3&b=10&c=2013&ignore=.csv";
  }

//function to download data from a url and store into a file
  function getCSVFile($URL, $outputFile) 
  {
      **$content = file_get_contents($URL);**     //goes to the file located at this link and downloads the full file contents as a string of data

      //replace a string which is the first parameter with the string in the second parameter. the string being replaced is in the third parameter
      $content = str_replace("Date,Open,High,Low,Close,Volume,Adj Close","", $content);

      //removes all white space
      $content = trim($content);

      //write a string into a file
      file_put_contents($outputFile, $content);      
  }

  function fileToDatabase($txtFile, $tableName)
  {
          $file = fopen($txtFile, "r");

          while(!feof($file))
          {
              $line = fgets($file);

              //separates a string 
              $pieces = explode(",", $line);

              //stock variables
              $date = $pieces[0];
              $open = $pieces[1];
              $high = $pieces[2];
              $low = $pieces[3];
              $close = $pieces[4];
              $volume = $pieces[5];
              // $adjclose = $pieces[6];   WE ARE NOT GOING TO USE THIS ONE USUALLY
              $amount_change = $close - $open;
              if($open!=0)
              { $percent_change = ($amount_change/$open)*100; }
              else $percent_change = 99999;


              //check if table exists or not
              $sql = "SELECT * FROM $tableName";
              $result = mysql_query($sql); 

              //if table doesn't exist
              if(!$result) 
              {
                  $sql_2 = "CREATE TABLE $tableName (date DATE , PRIMARY KEY(date), open FLOAT, high FLOAT, low FLOAT, close FLOAT, volume INT, amount_change FLOAT, percent_change FLOAT)";
                  mysql_query($sql_2);
              }

              //insert into table
              $sql_3 = "INSERT INTO $tableName(date, open, high, low, close, volume, amount_change, percent_change) VALUES ('$date','$open','$high','$low','$close','$volume','$amount_change','$percent_change')";
              mysql_query(sql_3);
          }
          fclose($file);
  }

  function main()
  {
    //i don't have this file yet
      $mainTickerFile = fopen("tickerMaster.txt","r");
      while(!feof($mainTickerFile))
      {
          $companyTicker = fgets($mainTickerFile);
          $companyTicker = trim($companyTicker);    //trim whitespace just in case

          $fileURL = createURL($companyTicker);    //create url for each stock ticker
          //create a directory path to each file for each ticker
          $companyTxtFile = "txtFiles/".$companyTicker.".txt";           //I NEED TO CREATE THIS FOLDER ON MY SERVER

          getCSVFile($fileURL, $companyTxtFile);

          fileToDatabase($companyTxtFile, $companyTicker);
      }
  }

  main();
?>


              <p><a href="secondpage.html">Run Script</a></p>
     </div>
 </body>
</html>
[function.file-get-contents]: failed to open stream: Connection refused in /srv/disk12/1368341/www/nemanja.co.nf/index.php on line 26