Reputation: 79
I am grabbing a .txt file and trying to reverse it, but I get this error when I try to, I don't understand it. Help please?
array_reverse() expects parameter 1 to be array, string given in ......
Here is the code:
$dirCont = file_get_contents($dir, NULL, NULL, $sPoint, 10240000);
$invertedLines = array_reverse($dirCont);
echo $invertedLines;
Upvotes: 0
Views: 8199
Reputation: 21
I think you need to pass the value on an array.
array_reverse(array($dircont));
This is working fine for me.
Upvotes: 1
Reputation: 4423
A string is not an array? Even if it were (as in C strings) it would not work as you expected. You'll need to split the file on line breaks (if you're trying to reverse to get the end of the file first).
$invertedLines = array_reverse(preg_split("/\n/", $dirCont));
Upvotes: 2