[advanced search]
Results from the most recent live auction are here.
22 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 01-19-2007, 05:21 AM   · #1
w1ww
NamePros Regular
 
w1ww's Avatar
 
Name: Tiago
Location: Mars.
Trader Rating: (15)
Join Date: Oct 2006
Posts: 427
NP$: 79.60 (Donate)
w1ww is a jewel in the roughw1ww is a jewel in the roughw1ww is a jewel in the rough
File Read [PHP]

Hello,

Using the file read function

PHP Code:
$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');


How can I make it to just read the last 5 lines of the file?

Thank you


Please register or log-in into NamePros to hide ads
__________________
w1ww is offline   Reply With Quote
Old 01-19-2007, 05:44 AM   · #2
lee101
NamePros Regular
 
Name: Lee
Location: United Kingdom
Trader Rating: (8)
Join Date: Mar 2006
Posts: 344
NP$: 2.90 (Donate)
lee101 is a jewel in the roughlee101 is a jewel in the roughlee101 is a jewel in the rough
PHP Code:
$file=file('testFile.php');
$lines=count($file);
$i=$lines-5;
while(
$i < $file){
echo
$file[$i];
$i++;
}

I think that may work, it isn't checked at all though, so there may be errors
__________________
http://bypasstopsite.com - Submit your proxy!
http://biggertwitter.com - Make twitter a bit bigger!
Currently Developing - Linux Screenshots
lee101 is offline   Reply With Quote
Old 01-19-2007, 05:48 AM   · #3
ahtum
DNOA Member
 
ahtum's Avatar
 
Name: Vlad
Trader Rating: (55)
Join Date: May 2006
Posts: 1,267
NP$: 1620.58 (Donate)
ahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud of
Ethan Allen Fund Find Marrow Donors!
Originally Posted by lee101
PHP Code:
$file=file('testFile.php');
$lines=count($file);
$i=$lines-5;
while(
$i < $file){
echo
$file[$i];
$i++;
}

I think that may work, it isn't checked at all though, so there may be errors



PHP Code:
$file = file('file.txt');

foreach(
$file as $line){
   echo
$line;
}


easier
__________________
www.vpslime.com
ahtum is offline   Reply With Quote
Old 01-19-2007, 06:03 AM   · #4
lee101
NamePros Regular
 
Name: Lee
Location: United Kingdom
Trader Rating: (8)
Join Date: Mar 2006
Posts: 344
NP$: 2.90 (Donate)
lee101 is a jewel in the roughlee101 is a jewel in the roughlee101 is a jewel in the rough
Originally Posted by ahtum

easier


Yes, but w1ww only wants the last 5 lines, that would display all of them
__________________
http://bypasstopsite.com - Submit your proxy!
http://biggertwitter.com - Make twitter a bit bigger!
Currently Developing - Linux Screenshots
lee101 is offline   Reply With Quote
Old 01-19-2007, 06:05 AM   · #5
w1ww
NamePros Regular
 
w1ww's Avatar
 
Name: Tiago
Location: Mars.
Trader Rating: (15)
Join Date: Oct 2006
Posts: 427
NP$: 79.60 (Donate)
w1ww is a jewel in the roughw1ww is a jewel in the roughw1ww is a jewel in the rough
ahtum,

Thanks for your input but lee101 solution works better, although, using his code I get the text, but I get also:

PHP Code:
Fatal error: Maximum execution time of 30 seconds exceeded in 3.php on line 7


what is wrong?

Thank you
__________________
w1ww is offline   Reply With Quote
Old 01-19-2007, 06:08 AM   · #6
lee101
NamePros Regular
 
Name: Lee
Location: United Kingdom
Trader Rating: (8)
Join Date: Mar 2006
Posts: 344
NP$: 2.90 (Donate)
lee101 is a jewel in the roughlee101 is a jewel in the roughlee101 is a jewel in the rough
what are lines 6-8 on 3.php, it sounds like another problem
edit:sorry, i'd wrote the code wrong, use this instead:
PHP Code:
$file=file('testFile.php');
$lines=count($file);
$i=$lines-5;
while(
$i < $lines){
echo
$file[$i];
$i++;
}
__________________
http://bypasstopsite.com - Submit your proxy!
http://biggertwitter.com - Make twitter a bit bigger!
Currently Developing - Linux Screenshots
lee101 is offline   Reply With Quote
Old 01-19-2007, 06:10 AM   · #7
w1ww
NamePros Regular
 
w1ww's Avatar
 
Name: Tiago
Location: Mars.
Trader Rating: (15)
Join Date: Oct 2006
Posts: 427
NP$: 79.60 (Donate)
w1ww is a jewel in the roughw1ww is a jewel in the roughw1ww is a jewel in the rough
It works now

Thank you guys!!
__________________
w1ww is offline   Reply With Quote
Old 01-19-2007, 07:07 AM   · #8
Matthew.
Stud Sausage
 
Location: England
Trader Rating: (25)
Join Date: Dec 2006
Posts: 1,545
NP$: 32.41 (Donate)
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
Adoption Breast Cancer Breast Cancer Cancer Survivorship
Topic is solved but just my input:

PHP Code:
$file = file('testFile.php');

for(
$i = 0; $i <= 5; $i++)
{
    echo
$file[count($file)-$i];
}


Just a little cleaner than using while

edit: Read below
__________________
My NamePros Tools
(firefox plugin, google gadget etc)

Last edited by Matthew. : 01-19-2007 at 02:20 PM.
Matthew. is offline   Reply With Quote
Old 01-19-2007, 02:07 PM   · #9
Dan
Buy my domains.
 
Dan's Avatar
 
Name: Dan
Trader Rating: (63)
Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 (Donate)
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
Autism Autism Autism Autism Autism Autism Autism
I know it's solved, too, but:

Matthew, that would show the lines backwards. (I think.)

PHP Code:
$file = file('testFile.php');

for (
$i = 5; $i >= 0; $i--) {
  echo
$file[count($file)-$i];
}


I don't know if that would work because count returns the number of items but that is one higher than the arrays highest key (if you can understand what I'm trying to say.) You might have to start with $i as 6 and just do $i > 0; :x
Dan is offline   Reply With Quote
Old 01-19-2007, 02:18 PM   · #10
Matthew.
Stud Sausage
 
Location: England
Trader Rating: (25)
Join Date: Dec 2006
Posts: 1,545
NP$: 32.41 (Donate)
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
Adoption Breast Cancer Breast Cancer Cancer Survivorship
Ahh good point Dan. That didn't even enter my head

(p.s. Your example is correct)
__________________
My NamePros Tools
(firefox plugin, google gadget etc)
Matthew. is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
Arcade Script Website Header Design RealTechNetwork
Advertise your business at NamePros
All times are GMT -7. The time now is 10:42 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0