开发者

What's wrong with my PHP unserialize?

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:1开发者_开发知识库308768615;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?


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+ 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜