Hello, I tried to search but found nothing. I need to read only x file line whiteout reading all other lines, is there any such functions? Thanks.
if it is a large file it`s simplest to do a shell_exec and get the first bit of the file. If its a small file you want the first line of you can do: $foo = file("filename"); $firstLine = $foo[0]; voila.
Well that's not what i was looking for. It reads whole first. I have php file witch content like this: There will be like 500-600lines... so each time then i need to read only one line i will need to read all lines first. I already have function like that. I need only to read x line in whatever place.
I think what you need is eval(); expressing a string as code. $foo = file("filename", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $firstLine = $foo[0]; eval($firstLine); echo $l; // user1|pass|84.32.1.2|0|3|100 PHP: note: you may need to remove the <? and ?>
I don't think there is a solution to read your file in random access (without loading it as a whole), unless you have lines of a fixed length (you may use fseek() in that case). If your goal is to speed up your script, why don't you use a SQLite database (support is built-in for PHP5)? You'll have both the advantages of a structured database and a plain file. Just my 2 cents.