At 1:31 PM -0700 8/30/01, Kyle Smith wrote:
>ok i have this code to do whats below, but its not working
>
>   <?php
>$fp = fopen("meh.txt","r");
>for($i=0;$i<2;$i++)
>{
>print "$fp[$i]";
>}
>?>


That's because $fp is a file POINTER, not the actual contents of the 
file. You might have been thinking of the file() function, which 
sucks the entire contents of the file into an array...very wasteful, 
if all you need are the first few lines. What you want here is:

        $fp = fopen("meh.txt","r");
        for($i=0;$i<2;$i++)
        {
        print fread($fp, 4096);
        }
or
        unset($FileArray);
        $fp = fopen("meh.txt","r");
        for($i=0;$i<2;$i++)
        {
        $FileArray[] = fread($fp, 4096);
        }

        foreach($FileArray as $line)
        {
        print $line;
        }

The second parameter in the fread function is the maximum line 
length; normally, that would be set to ma number larger than the 
maximum line length you're likely to encounter (unless you have long 
lines, and only need the first few characters of that line). See:

        http://www.php.net/manual/en/function.fopen.php
and
        http://www.php.net/manual/en/function.fread.php


Also, the line

        print "$fp[$i]";

isn't likely to work the way you expect; if $fp was an array, you'd 
get something like

        Array[0]
        Array[1]
        Array[2]

as the printout, since the $i, in quotes, wouldn't be interpreted as 
an array index. Use something like

        print $fp[$i];
or
        print "Some text here ".$fp[$i]." more text here";

instead.


>
>-lk6-
>http://www.StupeedStudios.f2s.com
>Home of the burning lego man!
>
>ICQ: 115852509
>MSN: [EMAIL PROTECTED]
>AIM: legokiller666


-- 
+------------------------ Open source questions? ------------------------+
| Steve Edberg                           University of California, Davis |
| [EMAIL PROTECTED]                               Computer Consultant |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+----------- http://pgfsun.ucdavis.edu/open-source-tools.html -----------+

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to