Parse CSV located on another server with PHP, JavaScript

I want to analyze a dynamically generated CSV file that is located on another server (Yahoo Finance), but from what I read, you cannot access content on another server using XMLHTTPRequest, at least not in CSV format.

I was thinking of a solution to this problem, and I would like to know if this is the "right" way or the best practice for this, since I am relatively new to development. This is what I came up with using PHP:

<?php
    $symbol = $_GET["s"];

    $path = "http://download.finance.yahoo.com/d/quotes.csv?s=" . $symbol . "&f=sl1d1t1c1ohgv&e=.csv";
    $yahooquote = fopen($path, "r");

    while(!feof($yahooquote))
    {
        $line = fgets($yahooquote, 1000);
        echo $line . "<br />";
    }

    fclose($yahooquote);
?>

This returns an html file that has the lines of the CSV file, and then I can use JavaScript / jQuery XMLHTTPRequest to parse it on the client side.

? - /? , , , 10 , +100. .

+1
4

. jQuery Yahoo ( CSV) Ajax, , .

+2

, .

, , :

script, cron X , csv yahoo .

, ajax, .

, , , , ,

cURL PHP

+3

cURL 5 .

function curl($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    return curl_exec($ch);
    curl_close ($ch);
}

$symbol = $_GET["s"];
$csv = "http://download.finance.yahoo.com/d/quotes.csv?s=" . $symbol . "&f=sl1d1t1c1ohgv&e=.csv";

$yahoo = curl($csv);

CSV $yahoo, (fopen, fwrite, fclose).

+2

@VerizonW: This tutorial on reading a remote file using PHP covers four methods (including the one you are currently using), I suggest you give it a read to find out which method you feel most comfortable with. I prefer to use cURL .

+1
source

Source: https://habr.com/ru/post/1787723/


All Articles