我的 PHP 反序列化出了什么问题?
我有一个包含以下内容的文件:(
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不直接使用 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?a+ 的意思是:“打开以进行读写;将文件指针放在文件末尾。如果文件不存在,则尝试创建它。”
如果您只想阅读“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:
See http://nl2.php.net/manual/en/function.fopen.php