Jump to content

Help an a "simple" file-function....


heidelberg77

Recommended Posts

Hi folks....

 

Getting mad on a simple function that used to work but does not anymore....

 

This is what it does - opens a csv file and grabs a value ($xco):

 

                $stock_info = file ("http://stooq.pl/q/l/?s=cl.f&f=sd2t2ohlc&e=csv");

$datx = $stock_info[0];

list ($x1, $x2, $x3, $x4, $x5, $x6, $x7) = split('[,]', $datx);

$xco = $x7;

 

Testing this function with a different csv source works fine (http://finance.yahoo.com/d/quotes.csv?s=USDJPY=X&f=sl1d1t1c1ohgv&e=.csv )

 

All my attempts to get it back to work failed so far.

The parameters of "http://stooq.pl/q/l/?s=cl.f&f=sd2t2ohlc&e=csv" can be changed ("http://stooq.pl/q/l/?s=cl.f&f=c&e=csv" gives out what i need only).

I have tested some alternatives like "fgetcsv", "file_get_contents", "fopen"... but nothing opens the stooq-file while it works fine with the yahoo-file.

 

Please help me!

It should not be that complicate to read a simple value.

 

Any help apreciated!

 

Link to comment
Share on other sites

Try this:

<?php

// read the list of stocks from the file.
    $stock_info = file("cl.f-1.csv");

// count how many stocks there are.
    $total_stocks = count($stock_info);

// go through the list and trim off the newline character.
    for ($counter = 0; $counter < $total_stocks; $counter++) {
        $stock_info[$counter] = trim($stock_info[$counter]);
    }

// implode the list into a single variable, put commas in, apply as $to value.
    $allStocks = implode(",", $stock_info);
    
echo $allStocks;

Link to comment
Share on other sites

I might have missunderstood you ;)

You have misunderstood me because of my EN  :'(

In both ways, the code woks fine to me:

<?php

// in a local machine
$stock_info = file("cl.f-1.csv");

// to remote server
$stock_info = file("http://stooq.pl/q/l/?s=cl.f&f=sd2t2ohlc&e=csv");

// print out result
CL.F,2012-07-20,22:59:05,92.5,92.61,90.94,91.59

 

 

Link to comment
Share on other sites

something is wrong....  :shrug:

 

<?php

 

$stock_info = file("http://stooq.pl/q/l/?s=cl.f&f=sd2t2ohlc&e=csv");

    $total_stocks = count($stock_info);

    for ($counter = 0; $counter < $total_stocks; $counter++) {

        $stock_info[$counter] = trim($stock_info[$counter]);

    }

    $allStocks = implode(",", $stock_info);

echo " Stock1: "; echo $allStocks;

 

echo "<br>";

 

$stock_info = file("http://finance.yahoo.com/d/quotes.csv?s=USDJPY=X&f=sl1d1t1c1ohgv&e=.csv");

    $total_stocks = count($stock_info);

    for ($counter = 0; $counter < $total_stocks; $counter++) {

        $stock_info[$counter] = trim($stock_info[$counter]);

    }

    $allStocks = implode(",", $stock_info);

echo " Stock2: "; echo $allStocks;

 

?>

 

gives out:

 

Stock1:

Stock2: "USDJPY=X",78.495,"7/20/2012","5:55pm",N/A,N/A,N/A,N/A,N/A

 

 

The Value "CL.F,2012-07-20,22:59:05,92.5,92.61,90.94,91.59" you keep receiving is exactly what I expect but it does not work out at my setting...

 

Link to comment
Share on other sites

Directive Local Value Master Value

allow_call_time_pass_reference On On

allow_url_fopen On On

allow_url_include Off Off

 

 

hmmm......I was expecting a server change done by the hoster but I was wondering why it still worked with the yahoo data.

I noticed when opening the links in my browser that the yahoo csv will open in excel while the stooq csv opens in editor (once downlodaed both files will open in excel).

 

Does my code above bring out the stooq result with your settings?

Link to comment
Share on other sites

no - Its the provider.

We had some changes there in the past and some to them affected the script where this error occured.

Do you have any idea what change of our hosting provider could have caused this error? This way I could simply ask them to chang this on Monday...

 

Link to comment
Share on other sites

Thank you Pikachu2000 and jazzman1 for all your help!

 

So it is not the script and nothing wrong with the providing source (stooq).

Must be a change done on the PHP settings done by my hosting provider.

 

This conclusion saved my weekend......working since yesterday on this issue - would have ruind my weekend without bringing any possible result.

 

I will contact our hoster on Monday.

 

Ayd idear what setting/change could be the reason?

Link to comment
Share on other sites

@Pikachu

to be used on my script or on the ini-file (shows nothing used at my script from post 7)?

 

@jazzman1  (hope it?s readable)

 

Directive Local Value Master Value

allow_call_time_pass_reference On On

allow_url_fopen On On

allow_url_include Off Off

always_populate_raw_post_data Off Off

arg_separator.input & &

arg_separator.output & &

asp_tags Off Off

auto_append_file no value no value

auto_globals_jit On On

auto_prepend_file no value no value

browscap /lib/browscap.ini /lib/browscap.ini

default_charset UTF-8 UTF-8

default_mimetype text/html text/html

define_syslog_variables Off Off

disable_classes no value no value

disable_functions no value no value

display_errors STDOUT STDOUT

display_startup_errors Off Off

doc_root no value no value

docref_ext no value no value

docref_root no value no value

enable_dl On On

error_append_string no value no value

error_log no value no value

error_prepend_string no value no value

error_reporting -1 6135

expose_php On On

extension_dir //lib/php/extensions/no-debug-non-zts-20060613 //lib/php/extensions/no-debug-non-zts-20060613

file_uploads On On

highlight.bg #FFFFFF #FFFFFF

highlight.comment #FF8000 #FF8000

highlight.default #0000BB #0000BB

highlight.html #000000 #000000

highlight.keyword #007700 #007700

highlight.string #DD0000 #DD0000

html_errors Off Off

ignore_repeated_errors On On

ignore_repeated_source On On

ignore_user_abort Off Off

implicit_flush Off Off

include_path .:/etc/php:/usr/local/share/php5.0:/usr/local/share/php5:/usr/local/share/php:/usr/share/php5.0:/usr/share/php5:/usr/share/php .:/etc/php:/usr/local/share/php5.0:/usr/local/share/php5:/usr/local/share/php:/usr/share/php5.0:/usr/share/php5:/usr/share/php

log_errors Off Off

log_errors_max_len 1024 1024

magic_quotes_gpc On On

magic_quotes_runtime Off Off

magic_quotes_sybase Off Off

mail.force_extra_parameters no value no value

max_execution_time 60 60

max_file_uploads 100 100

max_input_nesting_level 64 64

max_input_time 60 60

max_input_vars 1000 1000

memory_limit 64M 64M

open_basedir no value no value

output_buffering 0 0

output_handler no value no value

post_max_size 64M 64M

precision 12 12

realpath_cache_size 16K 16K

realpath_cache_ttl 120 120

register_argc_argv On On

register_globals On On

register_long_arrays On On

report_memleaks On On

report_zend_debug On On

safe_mode Off Off

safe_mode_exec_dir /bin /bin

safe_mode_gid Off Off

safe_mode_include_dir no value no value

sendmail_from no value no value

sendmail_path /bin/sendmail -t /bin/sendmail -t

serialize_precision 100 100

short_open_tag On On

SMTP localhost localhost

smtp_port 25 25

sql.safe_mode Off Off

track_errors Off Off

unserialize_callback_func no value no value

upload_max_filesize 64M 64M

upload_tmp_dir /tmp /tmp

user_dir no value no value

variables_order EGPCS EGPCS

xmlrpc_error_number 0 0

xmlrpc_errors Off Off

y2k_compliance On On

zend.ze1_compatibility_mode Off Off

 

Link to comment
Share on other sites

There is nothing wrong in the ini-file :(

Try this and tell us what happen.

 

<?php
error_reporting(-1);
ini_set('display_errors', 'On');
$stock_info = file_get_contents("http://stooq.pl/q/l/?s=cl.f&f=sd2t2ohlc&e=csv");
echo $stock_info;

Link to comment
Share on other sites

<?php

error_reporting(-1);

ini_set('display_errors', 'On');

$stock_info = file_get_contents("http://stooq.pl/q/l/?s=cl.f&f=sd2t2ohlc&e=csv");

echo " Test: "; echo $stock_info;

 

echo "<br>";

 

$stock_info = file("http://stooq.pl/q/l/?s=cl.f&f=sd2t2ohlc&e=csv");

    $total_stocks = count($stock_info);

    for ($counter = 0; $counter < $total_stocks; $counter++) {

        $stock_info[$counter] = trim($stock_info[$counter]);

    }

    $allStocks = implode(",", $stock_info);

echo " Stock1: "; echo $allStocks;

 

echo "<br>";

 

$stock_info = file("http://finance.yahoo.com/d/quotes.csv?s=USDJPY=X&f=sl1d1t1c1ohgv&e=.csv");

    $total_stocks = count($stock_info);

    for ($counter = 0; $counter < $total_stocks; $counter++) {

        $stock_info[$counter] = trim($stock_info[$counter]);

    }

    $allStocks = implode(",", $stock_info);

echo " Stock2: "; echo $allStocks;

?>

 

gives out:

 

Test:

Stock1:

Stock2: "USDJPY=X",78.495,"7/20/2012","5:55pm",N/A,N/A,N/A,N/A,N/A

 

:shrug:

Link to comment
Share on other sites

Hm....maybe you have a problem with "&" symbol in URL, use &amp html code.

What kind of browser do you use ?

Try this:

<?php
error_reporting(-1);
ini_set('display_errors', 'On');
$stock_info = file_get_contents("http://stooq.pl/q/l/?s=cl.f&f=sd2t2ohlc&e=csv");
echo $stock_info;

 

PS: I've noticed that, there is a "dot" symbol before csv url in yahoo.com

Link to comment
Share on other sites

no....same result.      :'(

 

I noticed the error on Thursday, called the hoster and they denied any recent changes on the server - so I was seaching for an error in my code and for a change on the supplyer side (stooq).....nothing.

The script works with you (prints the expected value) so it must be somthing with my server (error on the server or recent change of settings).

 

What could be the reson why the yahoo file is associated with excel (win opens it in excel if opend in a browser) while the stooq-csv seems not to be associated to excel (can you confirm this?). Possible csv-header error?

Could this be a relevant difference why the code works on my server with the yahoo-csv and not with the stooq-csv?

Link to comment
Share on other sites

 

What could be the reson why the yahoo file is associated with excel (win opens it in excel if opend in a browser) while the stooq-csv seems not to be associated to excel (can you confirm this?). Possible csv-header error?

Could this be a relevant difference why the code works on my server with the yahoo-csv and not with the stooq-csv?

 

I think there is a mime type set up in yahoo ->

http://filext.com/faq/office_mime_types.php

http://filext.com/file-extension/CSV

 

PS: Could you post a link to the script file to remote server. I want to check something.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.