首页 \ 问答 \ PHP cURL输出被截断(PHP cURL output is truncated)

PHP cURL输出被截断(PHP cURL output is truncated)

我试图用cURL加载一个JS文件,但结果是被截断了。 我也尝试过file_get_contents ,它仍然会被截断。
但我可以直接从浏览器访问.js文件。 除了user agentreferer之外, request headers没有任何内容,我将其包含在curl request

到底是怎么回事? 服务器弄乱了我吗?


I am trying to load a JS file with cURL, but the result is getting truncated. I also tried file_get_contents and it still truncates.
But I can access .js file directly from browser. There isn't anything in the request headers except user agent and referer, which I included in curl request.

What is going on? Is the server messing with me?


原文:https://stackoverflow.com/questions/28414416
更新时间:2023-08-03 13:08

最满意答案

如果您在“riepilogo”(摘要)表的标题中将月份表示为日期,则可以在公式中引用它们。 通过使用年份编号开始行,您可以轻松地将日期调整为年份中的更改。

例如,这里A2是年份,表示为简单数字。 B2,对于Gennaio(1月),使用Date(year,month,day)电子表格功能构建日期,在本例中为2013/1/1。 以下几个月使用EDATE(date,number_of_months)电子表格功能设置每个后续月份的第一天。

日期计算

现在,调整您的公式以引用该月的日期。 date操作符需要“yyyy-mm-dd”形式的日期,因此您需要使用TEXT函数对它们进行格式化。 以下是B3中的公式:

=INDEX(query('Scheda Intervento'!$C$2:$K$13;ʺselect sum (K) where (F >= date'ʺ & text(B$2,ʺyyyy-mm-ddʺ) & ʺ' and F < date 'ʺ & text(edate(B$2,1),ʺyyyy-mm-ddʺ) & ʺ' and C = 'ʺ & $A3 &ʺ')ʺ);2;1)

请注意,再次使用EDATE() - 这样公式仅依赖于同一列中的值。 不是必需的,但有用,因为它可以在电子表格的最右侧列中使用而无需修改。

您可以选择:而不是将年份放入A2中:

  • 使用=year(today())自动确定=year(today()) ,或
  • 引用电子表格中的另一个单元格。

编辑:Google电子表格日期的本地化问题

上述解决方案有效 - 但不是在意大利,也可能不在其他地区。 对于使用Locale == Italia的用户, Date()EDate()函数都会导致Google Spreadsheets中出现“解析错误”。

为了解决这个问题,下面的自定义函数将给定日期值转换为QUERY date运算符的正确格式的字符串。 有关自定义函数的详细信息,请参阅此博客条目 。 您只需从“工具”菜单中选择“脚本编辑器...”,将此代码块粘贴到编辑器工作区,然后保存。 您可以根据需要为脚本命名。

/**
 * Return the given date as a string formatted as 'yyyy-mm-dd'.
 */
function date2string(dateval) {
    var d = new Date(dateval);
    var dateArr = [];
    dateArr[0]=d.getFullYear();
    dateArr[1]=d.getMonth() + 1; //Months are zero based
    dateArr[2]=d.getDate();
    return dateArr.join('-');  
}

有了脚本,您就可以在电子表格中使用新功能date2string() 。 单元格C3的更新公式为:

=INDEX(query('Scheda Intervento'!$C$2:$K$13;"select sum (K) where (F >= date '" & date2string(C$2) & "' and F < date '" & date2string(D$2) & "' and C = '" & $A3 &"')");2;1)

INDEX问题()

这个公式还有另一个问题,它与INDEX()函数有关。 该函数需要一个数组作为输入,以及索引来索引数组中的项。 当QUERY()找到符合查询字符串条件的数据时,这很有效。 在这种情况下,从QUERY('Scheda Intervento'!$C$2:$K$13;"select...返回QUERY('Scheda Intervento'!$C$2:$K$13;"select...就像这个2行数组:

Sum
54

在这种情况下, INDEX([["Sum"],[54]];2;1)得到54 ,从数组的第2行第1列中选取。

但是如果我们没有匹配的数据,则没有第2行,我们有#REF错误。 我们可以通过简单地使用SUM()来添加数组的数值来避免这种情况。 当没有数字时,这将导致0 - 完美。

这是单元格C3的结果公式:

    =SUM(query('Scheda Intervento'!$C$2:$K$13;"select sum (K) where (F >= date '" & date2string(C$2) & "' and F < date '" & date2string(D$2) & "' and C = '" & $A3 &"')"))

If you expressed the months as dates in the header of your "riepilogo" (summary) sheet, you could reference them in your formula. By starting the row with a year number, you can easily have the dates adjust to changes in year.

For example, here A2 is the year, expressed as a simple number. B2, for Gennaio (January), builds the date using the Date(year,month,day) spreadsheet function, in this case 2013/1/1. The following months use the EDATE(date,number_of_months) spreadsheet function to set the first day of each subsequent month.

Date calculations

Now, adjust your formula to reference the date for the month. The date operator expects dates in the form "yyyy-mm-dd", so you need to use the TEXT function to format them. Here's what the formula in B3 will look like:

=INDEX(query('Scheda Intervento'!$C$2:$K$13;ʺselect sum (K) where (F >= date'ʺ & text(B$2,ʺyyyy-mm-ddʺ) & ʺ' and F < date 'ʺ & text(edate(B$2,1),ʺyyyy-mm-ddʺ) & ʺ' and C = 'ʺ & $A3 &ʺ')ʺ);2;1)

Note that EDATE() is used again - this is so that the formula relies only on values in the same column. Not a requirement, but helpful because it can be used in the right-most column of your spreadsheet without modification.

Instead of placing the year into A2, you could choose to:

  • have the year determined automatically using =year(today()), or
  • referencing another cell in your spreadsheet.

Edit: Localization Issues with Google Spreadsheet Dates

The above solution works - but not in Italy, and perhaps not in other locales. Both the Date() and EDate() functions result in "parse errors" in Google Spreadsheets for users with Locale == Italia.

To get around that, the custom function below converts a given date value into a string in the proper format for the date operator in QUERY. See this blog entry for more information about custom functions. All you need to do is select "Script Editor..." from the "Tools" menu, paste this block of code into the editor workspace, and save it. You can name the script anything you like.

/**
 * Return the given date as a string formatted as 'yyyy-mm-dd'.
 */
function date2string(dateval) {
    var d = new Date(dateval);
    var dateArr = [];
    dateArr[0]=d.getFullYear();
    dateArr[1]=d.getMonth() + 1; //Months are zero based
    dateArr[2]=d.getDate();
    return dateArr.join('-');  
}

With the script in place, you have a new function date2string() that you can use in your spreadsheet. The updated formula for cell C3 is:

=INDEX(query('Scheda Intervento'!$C$2:$K$13;"select sum (K) where (F >= date '" & date2string(C$2) & "' and F < date '" & date2string(D$2) & "' and C = '" & $A3 &"')");2;1)

Problem with INDEX()

There's another problem with this formula, and it's with the INDEX() function. That function expects an array as input, along with indices to index an item in the array. That works well when QUERY() finds data that meets the criteria in the query string. In that case, the return from QUERY('Scheda Intervento'!$C$2:$K$13;"select... is something like this 2-row array:

Sum
54

In that case, INDEX([["Sum"],[54]];2;1) results in 54, picked from row 2 col 1 of the array.

But if we have no matching data, there is no row 2, and we have a #REF error. We can avoid that by simply using SUM() to add the numeric values of the array. When there is no number, that will result in 0 - perfect.

Here's the resulting formula for cell C3:

    =SUM(query('Scheda Intervento'!$C$2:$K$13;"select sum (K) where (F >= date '" & date2string(C$2) & "' and F < date '" & date2string(D$2) & "' and C = '" & $A3 &"')"))

相关问答

更多

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)