file_get_contents()失败。(file_get_contents() failing. PHP)
以下两行代码有效。 他们成功地保存了这里和这里的数据。 我可以看到我服务器上的文件。
file_put_contents("vix.json", fopen("https://www.quandl.com/api/v3/datasets/YAHOO/INDEX_VIX.json?api_key=example", 'r')); file_put_contents("aaa.json", fopen("https://www.quandl.com/api/v3/datasets/MOODY/DAAAYLD.json?api_key=example", 'r'));
我可以使用以下方法从第一个文件成功提取数据:
$v = file_get_contents("vix.json");
但以下是停止我的PHP脚本:
$a = file_get_contents("aaa.json");
我注释掉上面的行并且脚本运行,包含它并且它失败了。
错误:
PHP Parse error: syntax error, unexpected '$a' (T_VARIABLE)
工作正在进行中。 目前谷歌搜索此错误。 任何去bug指针/建议非常感谢。
The following two lines of code work. They save the data from here and here down successfully. I can see the files on my server.
file_put_contents("vix.json", fopen("https://www.quandl.com/api/v3/datasets/YAHOO/INDEX_VIX.json?api_key=example", 'r')); file_put_contents("aaa.json", fopen("https://www.quandl.com/api/v3/datasets/MOODY/DAAAYLD.json?api_key=example", 'r'));
I can pull data successfully from the first file using this:
$v = file_get_contents("vix.json");
But the following is stopping my PHP script:
$a = file_get_contents("aaa.json");
I comment out the above line and the script runs, include it and it fails.
Error:
PHP Parse error: syntax error, unexpected '$a' (T_VARIABLE)
Work in progress. Currently googling this error. Any de-bug pointers/suggestions much appreciated.
原文:https://stackoverflow.com/questions/35166323
最满意答案
不,
File.ReadAllLines()
将指定为文本文件的文件视为。 zip文件不是那样的。 自己做这件事是微不足道的:public IEnumerable<string> ReadAllZippedLines(string filename) { using (var fileStream = File.OpenRead(filename)) { using (var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress)) { using (var reader = new StreamReader(gzipStream)) { yield return reader.ReadLine(); } } } }
No,
File.ReadAllLines()
treats the file specified as text file. A zipfile isn't that. It's trivial to do it yourself:public IEnumerable<string> ReadAllZippedLines(string filename) { using (var fileStream = File.OpenRead(filename)) { using (var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress)) { using (var reader = new StreamReader(gzipStream)) { yield return reader.ReadLine(); } } } }
相关问答
更多-
切换到包含.gz文件的目录,并且1)指定gunzip.exe的路径或2)将包含gunzip.exe的目录添加到PATH变量。 "C:\path\to\gunzip.exe" -c filename.gz | mysql -u.. -p.. -P.. -h dbname Change to the directory containing the .gz file and either 1) specify the path to gunzip.exe or 2) add the directory con ...
-
你可以写一个逐行读取的方法,如下所示: public IEnumerable
ReadLines(Func streamProvider, Encoding encoding) { using (var stream = streamProvider()) using (var reader = new StreamReader(stream, encoding)) { ... -
当您的浏览器向Web服务器发送HTTP请求时,它可以指定Accept-Encoding字段以指示它支持的压缩模式: GET /scripts/jquery.min.js HTTP/1.1 Host: www.example.com Accept-Encoding: gzip, deflate 服务器然后可以选择这些模式之一(但不必),并在响应头中指定它: HTTP/1.1 200 OK Content-Encoding: gzip etc. 所以,如果Web服务器配置为gzip JavaScript文件 ...
-
使用@ Rhymoid的建议,你的代码应该看起来像这样(未经测试): #!/usr/bin/env python import logging import gzip import StringIO from base64 import b64decode logging.basicConfig(filename='out.log', level=logging.DEBUG) compressed_data = 'H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiA ...
-
使用LINQ时,File.ReadAllLines是否延迟加载?(Is File.ReadAllLines lazy loaded when using with LINQ Where?)[2022-08-29]
File.ReadAllLines不是延迟加载的,它会将所有内容加载到内存中。 string[] allLines = File.ReadAllLines(filePath); 如果要使用LINQ的延迟执行,可以使用File.ReadLines : var fileLines = File.ReadLines(filePath) .Where(line => { line = line.Trim(); return line.Contains("hello ... -
我道歉 - 我被MSDN文档误导,该文档说当传递给方法的路径参数指定一个只读文件时抛出UnauthorizedAccessException。 实际上,尽管有MSDN文档,但您可以为只读文件发出ReadAllLines。 I apologise - I was misled by the MSDN documentation, which says that the UnauthorizedAccessException is thrown when the path argument passed to ...
-
不, File.ReadAllLines()将指定为文本文件的文件视为。 zip文件不是那样的。 自己做这件事是微不足道的: public IEnumerable
ReadAllZippedLines(string filename) { using (var fileStream = File.OpenRead(filename)) { using (var gzipStream = new GZipStream(fileStream, Compressio ... -
如果文件格式不可拆分,则无法避免在一个核心上完整地读取文件。 为了并行化工作,您必须知道如何将工作块分配给不同的计算机。 在gzip的情况下,假设您将其分成128M块。 第n个块依赖于第n-1个块的位置信息来知道如何解压缩,这取决于n-2-nd块,依此类推到第一个块。 如果要并行化,则需要使此文件可拆分。 一种方法是解压缩并解压缩它,或者你可以解压缩它,将它分成几个文件(每个并行任务一个文件),然后gzip每个文件。 If the file format is not splittable, then th ...
-
您仍然必须遍历这两个文件,但这更清晰: import gzip from itertools import islice, izip file1 = r"path\to\file1.gz" file2 = r"path\to\file2.gz" with gzip.open(file1) as f1, gzip.open(file2) as f2: for line1, line2 in islice(izip(f1, f2)), 3, None, 4): compare(lin ...
-
您尝试使用的方法是java.nio.file.Files的成员 - 但Android上不存在该类(实际上是该包)。 即使Java 7版本存在,您也尝试使用Java 8中引入的方法。您导入的Files类是android.provider.MediaStore.Files ,这是一个完全不同的类。 即使它被编译,你提供的路径看起来非常像Windows路径,这在Android设备上不起作用...... The method you're trying to use is a member of java.nio. ...