加载 PHP 时 Browscap.ini 抛出错误(命令行 - PHP_CLI)
我有一个总结浏览器统计信息的 cronjob。该 cronjob 加载数据,然后使用 get_browser() PHP 函数解析浏览器信息。
这就是我所做的:
cd /etc/php5/cli/conf.d
me@ubutnu:/etc/php5/cli/conf.d$ sudo wget http://browsers.garykeith.com/stream.asp?Lite_PHP_BrowsCapINI -O browscap.ini
2011-09-30 15:14:18 (890 KB/s) - `browscap.ini' saved [185384/185384]
然后 cronjob 运行:
php /usr/local/cron/summarizeStats.php --option=browserStats --date=yesterday
我收到此错误:
PHP: syntax error, unexpected $end, expecting ']' in /etc/php5/cli/conf.d/browscap.ini on line 51
我做错了什么?谢谢
I have a cronjob that summarize browser statistics. This cronjob loads data and then use the get_browser() PHP function to parse the browser information.
Here's what I did:
cd /etc/php5/cli/conf.d
me@ubutnu:/etc/php5/cli/conf.d$ sudo wget http://browsers.garykeith.com/stream.asp?Lite_PHP_BrowsCapINI -O browscap.ini
2011-09-30 15:14:18 (890 KB/s) - `browscap.ini' saved [185384/185384]
Then the cronjob run:
php /usr/local/cron/summarizeStats.php --option=browserStats --date=yesterday
and I get this error:
PHP: syntax error, unexpected $end, expecting ']' in /etc/php5/cli/conf.d/browscap.ini on line 51
What am I doing wrong? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这些 browsercap 文件现在似乎存在错误。它们似乎包含未转义的分号“;”在浏览器规范中。您可以使用这个小脚本来解决这个问题:
There is seemingly right now an error with those browsecap files. They seem to contain unescaped semicolons ";" in the browser spec. You can fix that using this little script:
有点晚了,但是使用不修改的文件仍然存在问题。我正在使用以下脚本下载并更改 browscap.ini,以便它可以在我的服务器上运行。
解释
\'
转义每个;
(;;;;)
。这可以在搜索部分使用^\;
进行优化,在替换部分仅使用单个;
进行优化,在我放置第三个 sed 之前需要测试'*'
不要忘记调整您的 browscap.ini 最终目的地。另外,更新后无需重新启动 Apache 或 PHP,因此将此脚本放在某处并设置 cron 作业。
A little bit late, but there are still problems with using file without modifications. I'm using following script to download and change browscap.ini so it can work on my server.
Explanation
;
with\'
(;;;;)
. This could be optimised with something like^\;
in search part, and just single;
in replace part, need to test that before I put'*'
Don't forget to adjust your browscap.ini finial destination. Also there is no need for Apache or PHP restart after update, so put this script somewhere and setup cron job.
sed
可用于转义分号,如下所示:这也将捕获所有注释,但您可以再次使用
sed
来捕获这些注释。如此处所述 github.com/browscap/browscap/issues/119
sed
can be used to escape the semi-colon like so:This will catch all the comments as well but you could use
sed
again to catch those.As described here github.com/browscap/browscap/issues/119