0

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?

johnsyweb
  • 136,902
  • 23
  • 188
  • 247
some guy
  • 53
  • 3

2 Answers2

3

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

hoppa
  • 3,011
  • 18
  • 21
Spudley
  • 166,037
  • 39
  • 233
  • 307
1

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

hoppa
  • 3,011
  • 18
  • 21
  • And for simply slurping in the entire contents of a file, might as well just use `file_get_contents()`. – Marc B Jun 22 '11 at 19:09