D3 proxy reader via PHP

In existing SO literature, I have seen examples of using jquery and PHP for proxy data:

JQuery

function loadTheUrl(x){      
    $.ajax({ url: 'loader.php',
         data: {url: x},
         type: 'get',
         success: function(output) {
                      $('.loading-space').html(output);
                  }
            });

  } 

Php

<?php
$doc = new DOMDocument();
$doc->loadHTML(file_get_contents($_GET['https://www.google.com/finance/getprices?q=.NSEI&x=NSE&i=600&p=1d&f=d,o']));
echo $doc->saveHTML();

Here's what the first few lines of data look like at the URL given in PHP above. This is just plain text text, for example:

MARKET_OPEN_MINUTE=570
MARKET_CLOSE_MINUTE=960
INTERVAL=300
COLUMNS=DATE,OPEN
DATA=
TIMEZONE_OFFSET=-240
a1521120900,555.45
1,554.53
2,554.07
3,553.9
4,552.67
...

As far as I know, PHP is correct. For my use case, I need to replicate the above jquery using d3. I was hoping d3 would have something to use to interact with the data that my php file is spitting out.

, , , (.. d3.text(), d3.csv() et all) , d3.text('https://www.google.com/finance...') - . , , Google php , . , (, , ).

d3.text() php , . , : d3.text('my_loader.php'). NaN, , - . , . , . . IDE. d3- , , . , PHP. , d3 PHP-, URL, PHP. , data, d3.text() , PHP.

: , d3 PHP, ? , d3 / - , (PHP ).

+4
2

URL-, , $_GET.

, , :

$_GET = ['url' => 'some_url'];

:

$_GET['https://www.google.com/finance/getprices?q=.NSEI&x=NSE&i=600&p=1d&f=d,o]

( ).

$_GET['url']

:

<?php
header('Content-Type: text/plain');
echo file_get_contents($_GET['url']);

, .

, , url. (? &). , bjorking $_GET, , , https://www.google.com/finance/getprices?q=.NSEI. URL- encodeURIComponent:

var url = encodeURIComponent('https://www.google.com/finance/getprices?q=.NSEI&x=NSE&i=600&p=1d&f=d,o');
d3.text('/path/to/myscript.php?url=' + url);
+1

ajax, d3.text('https://www.google.com/finance...'), d3.text('mymethod.php') , , html :

<?php header('Content-Type: text/plain'); $file = file_get_contents('https://www.google.com/finance/getprices?q=.NSEI&x=NSE&i=600&p=1d&f=d,o'); echo $file;

+1
source

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


All Articles