|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
using fread()
Is there a way to read from a specific LINE in a text file using the fread function? I've searched PHP.net and PHPBuilder to no avail. It appears you can start from the beginning, start from the end, or go to a certain bit in the file.
Can I call the file $textfile and explode $textfile at the "n" or some trick like that? -Adam |
|
#2
|
|||
|
|||
|
RE: using fread()
You should be able to read it in using the file function. This will return an array. Each element of the array matches up to a line of the file...then you can address line 10 of the file by doing:
$myfile = file('/path/to/file.txt'); echo $myfile[9]; Note that I addressed it as 9, that's because the array starts at 0.... Hope that helps.. |
|
#3
|
|||
|
|||
|
RE: using fread()
worked perfectly! I listed 600 songs in a file, and used this simple little code...
<? $songarray = file("../includes/songs.inc"); $songcount = count($songarray); $songcount = ($songcount -1); $songnum = rand(0, $songcount); ?> <font size=0 face=verdana>song of the minute <br> <span class="sotm"> Â* <?=$songarray[$songnum]?> </span><br> Thanks Matt |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > using fread() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|