How to pick a specific row in a file?

This is a discussion on How to pick a specific row in a file? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello.. Lets say I want to pick row number #3 in text.txt. $row[] = file['text.txt']; How to do ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-31-2004
Roger Saarva
 
Posts: n/a
Default How to pick a specific row in a file?

Hello..

Lets say I want to pick row number #3 in text.txt.

$row[] = file['text.txt'];

How to do now..? :-P

Thanks alot in Advance.


Reply With Quote
  #2 (permalink)  
Old 07-31-2004
steve
 
Posts: n/a
Default Re: How to pick a specific row in a file?

"Roger Saarva" wrote:
> Hello..
>
> Lets say I want to pick row number #3 in text.txt.
>
> $row[] = file[’text.txt’];
>
> How to do now..?
>
> Thanks alot in Advance.


$row[2] is the element you are looking for. One less than 3 since the
array is zero-based.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-pick-spe...ict135280.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=451807
Reply With Quote
  #3 (permalink)  
Old 08-01-2004
Colin McKinnon
 
Posts: n/a
Default Re: How to pick a specific row in a file?

steve spilled the following:

> "Roger Saarva" wrote:
> > Hello..
> >
> > Lets say I want to pick row number #3 in text.txt.
> >
> > $row[] = file[’text.txt’];
> >
> > How to do now..?
> >
> > Thanks alot in Advance.

>
> $row[2] is the element you are looking for. One less than 3 since the
> array is zero-based.
>


Nope - coz he assigned the array of lines to the next free elemnt in the
array - using the code above, the OP really wants $row[*something*][2]...

I expect he really meant to write:
$row=file('text.txt');

C.
Reply With Quote
  #4 (permalink)  
Old 08-01-2004
Andreas Saarva
 
Posts: n/a
Default Re: How to pick a specific row in a file?


"Colin McKinnon"
<colin.thisisnotmysurname@ntlworld.deletemeunlessU RaBot.com> skrev i
meddelandet news:YoWOc.418$E25.268@newsfe3-gui.ntli.net...
> steve spilled the following:
>
> > "Roger Saarva" wrote:
> > > Hello..
> > >
> > > Lets say I want to pick row number #3 in text.txt.
> > >
> > > $row[] = file['text.txt'];
> > >
> > > How to do now..?
> > >
> > > Thanks alot in Advance.

> >
> > $row[2] is the element you are looking for. One less than 3 since the
> > array is zero-based.
> >

>
> Nope - coz he assigned the array of lines to the next free elemnt in the
> array - using the code above, the OP really wants $row[*something*][2]...
>
> I expect he really meant to write:
> $row=file('text.txt');
>
> C.


Hmm... let's start it from the beginning... hehe sorry for that, but
anyways...

Lets assume I want to have the row 127 in the html code of a site assigned
in the variable $row_127, lets say www.example.com, then how would I have to
write?

Thank you.


Reply With Quote
  #5 (permalink)  
Old 08-02-2004
Hilarion
 
Posts: n/a
Default Re: How to pick a specific row in a file?

<?php
$row_127 = file('text.txt')[126];
?>

or

<?php
$rows = file('text.txt');
$row_127 = $rows[126];
?>

or

....


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:37 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0