heidelberg77 Posted July 21, 2012 Share Posted July 21, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/ Share on other sites More sharing options...
jazzman1 Posted July 21, 2012 Share Posted July 21, 2012 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; Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363251 Share on other sites More sharing options...
heidelberg77 Posted July 21, 2012 Author Share Posted July 21, 2012 same situation -> when replacing "cl.f-1.csv" with the yahoo-link it works. While the stooq-link (http://stooq.pl/q/l/?s=cl.f&f=sd2t2ohlc&e=csv) fails. Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363256 Share on other sites More sharing options...
heidelberg77 Posted July 21, 2012 Author Share Posted July 21, 2012 opening the stooq-file as txt insted of csv (http://stooq.pl/q/l/?s=cl.f&f=sd2t2ohlc&e=txt) works but i still can not open it/get the output into a variable... Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363259 Share on other sites More sharing options...
jazzman1 Posted July 21, 2012 Share Posted July 21, 2012 same situation -> when replacing "cl.f-1.csv" with the yahoo-link it works. While the stooq-link (http://stooq.pl/q/l/?s=cl.f&f=sd2t2ohlc&e=csv) fails. Everything works fine with "cl.f-1.csv" by me. There is something wrong in your code. What result do you expect to be ? Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363266 Share on other sites More sharing options...
heidelberg77 Posted July 21, 2012 Author Share Posted July 21, 2012 I might have missunderstood you Did you mean "http://stooq.pl/q/l/?s=cl.f-1.csv" as the link used in "$stock_info = file("http://stooq.pl/q/l/?s=cl.f-1.csv");" or are you doing a download to a local dir first? Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363267 Share on other sites More sharing options...
jazzman1 Posted July 21, 2012 Share Posted July 21, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363269 Share on other sites More sharing options...
heidelberg77 Posted July 21, 2012 Author Share Posted July 21, 2012 something is wrong.... <?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... Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363274 Share on other sites More sharing options...
jazzman1 Posted July 21, 2012 Share Posted July 21, 2012 Open up php.ini file, find "allow_url_fopen" and tell me what kind value there is ? Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363276 Share on other sites More sharing options...
heidelberg77 Posted July 21, 2012 Author Share Posted July 21, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363278 Share on other sites More sharing options...
jazzman1 Posted July 21, 2012 Share Posted July 21, 2012 Can you edit php.ini file or it's your hosting provider? Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363280 Share on other sites More sharing options...
heidelberg77 Posted July 21, 2012 Author Share Posted July 21, 2012 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... Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363281 Share on other sites More sharing options...
Pikachu2000 Posted July 21, 2012 Share Posted July 21, 2012 The code in the reply #7 works just fine for me, with no changes at all. output: Stock1: CL.F,2012-07-20,22:59:05,92.5,92.61,90.94,91.59 Stock2: "USDJPY=X",78.495,"7/20/2012","5:55pm",N/A,N/A,N/A,N/A,N/A Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363283 Share on other sites More sharing options...
heidelberg77 Posted July 21, 2012 Author Share Posted July 21, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363285 Share on other sites More sharing options...
jazzman1 Posted July 21, 2012 Share Posted July 21, 2012 Could you give us a php version of you hoster ? Use the phpinfo() function and link to us. Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363287 Share on other sites More sharing options...
heidelberg77 Posted July 21, 2012 Author Share Posted July 21, 2012 It?s a PHP Version 5.2.17 Any specific part of the ini? Full phpinfo() function as a link would also show up password information Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363291 Share on other sites More sharing options...
Pikachu2000 Posted July 21, 2012 Share Posted July 21, 2012 See if any errors are generated by the script. Add the following immediately after your opening <?php tag error_reporting(-1); ini_set('display_errors', 'On'); Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363293 Share on other sites More sharing options...
jazzman1 Posted July 21, 2012 Share Posted July 21, 2012 It?s a PHP Version 5.2.17 Any specific part of the ini? Full phpinfo() function as a link would also show up password information I want to see "PHP Core Part". Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363294 Share on other sites More sharing options...
heidelberg77 Posted July 21, 2012 Author Share Posted July 21, 2012 @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 Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363297 Share on other sites More sharing options...
jazzman1 Posted July 21, 2012 Share Posted July 21, 2012 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; Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363303 Share on other sites More sharing options...
heidelberg77 Posted July 21, 2012 Author Share Posted July 21, 2012 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363304 Share on other sites More sharing options...
jazzman1 Posted July 21, 2012 Share Posted July 21, 2012 Hm....maybe you have a problem with "&" symbol in URL, use & 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 Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363307 Share on other sites More sharing options...
heidelberg77 Posted July 21, 2012 Author Share Posted July 21, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363311 Share on other sites More sharing options...
jazzman1 Posted July 21, 2012 Share Posted July 21, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363316 Share on other sites More sharing options...
heidelberg77 Posted July 21, 2012 Author Share Posted July 21, 2012 hmmmm......so it seems to be a change in the ini of our server done by the hoster.....but why does the error show up for the stooq-csv and not for the yahoo.csv? I am really getting mad on this one...... :'( Quote Link to comment https://forums.phpfreaks.com/topic/266041-help-an-a-simple-file-function/#findComment-1363320 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.