PHP fgetcsv 遇到致命错误:在 Firefox 上超出最大执行时间
首先我猜想 PHP 中的“致命错误:超出最大执行时间”是服务器端错误,不应该依赖于浏览器版本,对吧?但似乎确实如此!?!
我有这段代码来读取来自表单文本区域的 csv 数据。
$handle = tmpfile();
fwrite($handle, $csvclip);
fseek($handle, 0);
while (!feof($handle)) {
$r = fgetcsv($handle, 1000, $delimiter, '"'); <---- Here it gives Fatal Error
print $r[0];
}
数据就是这样,没什么特别的,4列3行。
a b 1 2
c d 3 4
e f 5 6
代码适用于所有浏览器(IE、Chrome 等),我可以看到我解析的数据,除了 Firefox!!!!我在不同的电脑上测试过,但都是一样的。所有浏览器都可以,但 Firefox 对于具有“fgetcsv”的行给出“致命错误:超出最大执行时间”
我正在使用 PHP 版本 5.2.10 和 2 个不同的 Firefox 版本 3.5.16 和 3.6.6
以前有人见过这个问题吗?
编辑:代码在两台不同的 Linux 服务器 CentOS 5.3 和 5.5 上进行测试,使用两台具有所有浏览器的不同 PC。
编辑2:已解决
好的,我发现了问题。 $delimiter 值来自具有 3 个值“,”“;”和“\t”,浏览器将“\t”显示为空格,我没有注意它。
看来 firefox 正在对 \t 做一些事情,所以 PHP 不明白它是制表符。但其他浏览器按预期发送 \t 。
如果我像 fgetcsv($handle, 1000, "\t", '"') 那样对 "\t" 进行硬编码,那么在 Firefox 上也可以正常工作。
第一次 Firefox 给我带来了那么多麻烦,而不是 IE :)
First of all I guess that "fatal error: maximum execution time exceeded" in PHP is a server side error and shouldn't depend on browser version, right? But seems it does!?!
I have this code to read csv data coming from a text area in a form.
$handle = tmpfile();
fwrite($handle, $csvclip);
fseek($handle, 0);
while (!feof($handle)) {
$r = fgetcsv($handle, 1000, $delimiter, '"'); <---- Here it gives Fatal Error
print $r[0];
}
And data is this, nothing special, 4 columns and 3 rows.
a b 1 2
c d 3 4
e f 5 6
Code works on all browsers (IE, Chrome, e.t.c), I can see my parsed data except Firefox!!!!! I tested on different PCs but same. All browsers are ok but Firefox gives "Fatal error: Maximum execution time exceeded" for line having "fgetcsv"
I'm using PHP Version 5.2.10 and 2 different firefox versions 3.5.16 and 3.6.6
Anyone have seen this problem before?
Edit: Code is tested on two different linux servers CentOS 5.3 and 5.5, using two different PC having all browsers.
Edit 2: SOLVED
Ok I found the problem. $delimiter value comes from a having 3 values "," ";" and "\t" which browsers display "\t" as spaces in and I didn't pay attention to it.
Seems firefox is doing something to \t so PHP doesn't understand that it's tab. But other browsers sends \t as expected.
If I hardcode "\t" like fgetcsv($handle, 1000, "\t", '"') works fine also with firefox.
First time Firefox caused me that much trouble and not IE :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将以下内容添加到脚本顶部:
这应该禁用脚本运行的时间限制。
Add the following to the top of your script:
This should disable the time limit for your script to run.
不确定这是否是这里的问题,但请查看 Tom 在 2006 年 10 月 24 日 10:27 在 feof() 页面
Not sure if it's the problem here, but take a look at Tom's comments from 24-Oct-2006 10:27 on the feof() page
好吧,我发现了问题。 $delimiter 值来自具有 3 个值“,”“;”和“\t”,浏览器将“\t”显示为空格,我没有注意它。
看来 firefox 正在对 \t 做一些事情,所以 PHP 不明白它是制表符。但其他浏览器按预期发送 \t 。
如果我像 fgetcsv($handle, 1000, "\t", '"') 那样硬编码“\t”,那么在 Firefox 中也可以正常工作。
Ok I found the problem. $delimiter value comes from a having 3 values "," ";" and "\t" which browsers display "\t" as spaces in and I didn't pay attention to it.
Seems firefox is doing something to \t so PHP doesn't understand that it's tab. But other browsers sends \t as expected.
If I hardcode "\t" like fgetcsv($handle, 1000, "\t", '"') works fine also with firefox.