我的 PHP 反序列化出了什么问题?

发布于 2024-11-16 14:33:54 字数 908 浏览 3 评论 0原文

我有一个包含以下内容的文件:(

a:12:{s:12:"a2.twimg.com";i:1308768611;s:12:"a1.twimg.com";i:1308768611;s:12:"a0.twimg.com";i:1308768612;s:12:"a3.twimg.com";i:1308768612;s:8:"this.com";i:1308768613;s:15:"f.prototype.com";i:1308768613;s:15:"c.prototype.com";i:1308768614;s:15:"a.prototype.com";i:1308768614;s:5:"w.com";i:1308768615;s:5:"s.com";i:1308768615;s:5:"f.com";i:1308768615;s:5:"h.com";i:1308768615;}

它是 twitter.com 上列出的域数组作为键,时间戳作为值)

如果我调用:(

unserialize(fread($recentfile, filesize("./neptune_output/recent"))) 

"./neptune_output/recent"$recentfile)

它失败了,但是如果我调用 unserialize 并粘贴该字符串,它就会起作用。

我使用以下代码打开该文件。

$recentfile = fopen("./neptune_output/recent", 'a+')

我尝试将 fopen 模式设置为 'c+''a+b' 但它不起作用。

我需要发布更多代码吗?

I have a file with the contents:

a:12:{s:12:"a2.twimg.com";i:1308768611;s:12:"a1.twimg.com";i:1308768611;s:12:"a0.twimg.com";i:1308768612;s:12:"a3.twimg.com";i:1308768612;s:8:"this.com";i:1308768613;s:15:"f.prototype.com";i:1308768613;s:15:"c.prototype.com";i:1308768614;s:15:"a.prototype.com";i:1308768614;s:5:"w.com";i:1308768615;s:5:"s.com";i:1308768615;s:5:"f.com";i:1308768615;s:5:"h.com";i:1308768615;}

(It's an array of domains listed on twitter.com as keys and a timestamp as values)

If I call:

unserialize(fread($recentfile, filesize("./neptune_output/recent"))) 

("./neptune_output/recent" is the location of the $recentfile)

It fails, but if I call unserialize with that string pasted in, it works.

I use the following code to open the file.

$recentfile = fopen("./neptune_output/recent", 'a+')

I've tried putting the fopen mode as 'c+' and 'a+b' but it won't work.

Do I need to post more code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Hello爱情风 2024-11-23 14:33:54

为什么不直接使用 file_get_contents() 来读取它,而不是乱七八糟地打开它并计算出文件大小呢?

Why don't you just read it with file_get_contents() rather than messing about with opening it and working out the file size?

沉睡月亮 2024-11-23 14:33:54

a+ 的意思是:“打开以进行读写;将文件指针放在文件末尾。如果文件不存在,则尝试创建它。”

如果您只想阅读“r”就足够了:

$recentfile = fopen("./neptune_output/recent", 'r')

请参阅http://nl2。 php.net/manual/en/function.fopen.php

a+ means: "Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it."

If you just want to read "r" is enough:

$recentfile = fopen("./neptune_output/recent", 'r')

See http://nl2.php.net/manual/en/function.fopen.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文