Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to read contents in a text file and display in browser?

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
i have a couple paragraphs stored in a text file and i want to display the contents on screen...

the only problem is i can only access the first line.

here's what i'm using...

Code:
$cfile = "offer-text/".$offer.".txt";
open (COUNTER, "$cfile");
$offerInfo = <COUNTER>;
close (COUNTER);

once i display the contents stored in $offerInfo, it only shows me the first line of file.

any ideas?

- g
 

try reading the file in to an array as opposed to a scalar..

Code:
@offerInfo = <COUNTER>;

instead of

Code:
$offerInfo = <COUNTER>;
 
Or maybe something like this...

open(COUNTER, "$cfile") or die;
while (<COUNTER>)
{
my $line = $_;
print $line . "\n";

}
close COUNTER;

Mark
 
or:

Code:
open(COUNTER, "$cfile") or die;
print <COUNTER>;
close COUNTER;





------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top