Re: [PHP] Printing files
$data = file ($certain_file); echo "{$data[0]}\n"; echo "{$data[3]}\n"; echo "{$data[7]}\n"; Valentin Petruchek (aki Zliy Pes) *** Cut the beginning *** http://zliypes.com.ua mailto:[EMAIL PROTECTED] - Original Message - From: "John Gurley" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, February 13, 2002 1:55 PM Subject: [PHP] printing files > Just a quick question, > is there a way to echo in your php code lines of a file that you specify. > i.e. you want to output lines 1,4,7 of a certain text file > Thanks > John > > > > _ > Join the worlds largest e-mail service with MSN Hotmail. > http://www.hotmail.com > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] printing files
$data = file ($certain_file); echo "{$data[0]}\n"; echo "{$data[3]}\n"; echo "{$data[7]}\n"; Valentin Petruchek (aki Zliy Pes) *** Cut the beginning *** http://zliypes.com.ua mailto:[EMAIL PROTECTED] - Original Message - From: "John Gurley" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, February 13, 2002 1:55 PM Subject: [PHP] printing files > Just a quick question, > is there a way to echo in your php code lines of a file that you specify. > i.e. you want to output lines 1,4,7 of a certain text file > Thanks > John > > > > _ > Join the worlds largest e-mail service with MSN Hotmail. > http://www.hotmail.com > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] printing files
The only way that works fine for me is to read a file char by char. When you read the \n character add the readen chars in array's position. Here is an example $fp = fopen ("myfile","r"); $txtarr = array();// array to store each line of your file $linenum = 1; // just a counter $linetext = ""; // string to put characters. Empty this string when you move to new line while ( !feof( $fp ) ){ $ch = fgetc( $fp );// read a char $linetext .= $ch; // added to string if ( $ch=="\n" ){// is it a new line? $txtarr[$linenum] = $linetext; // fill your array $linenum++; // counter ++ $linetext = ""; // empty line string; } } echo $txtarr[0]; // this outputs the1st line of your file etc. - Original Message - From: "John Gurley" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, February 13, 2002 1:55 PM Subject: [PHP] printing files > Just a quick question, > is there a way to echo in your php code lines of a file that you specify. > i.e. you want to output lines 1,4,7 of a certain text file > Thanks > John > > > > _ > Join the worlds largest e-mail service with MSN Hotmail. > http://www.hotmail.com > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] printing files
Hy, John Gurley wrote: > Just a quick question, > is there a way to echo in your php code lines of a file that you specify. > i.e. you want to output lines 1,4,7 of a certain text file use the fopen and fread functions, to read lines from a file, only put the wanted lines into a string and output this string. hth, henning -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] printing files
just put the lines in an array, each array element contains a line... and then just print the specified array elements... Edward - Original Message - From: "John Gurley" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, February 13, 2002 12:55 PM Subject: [PHP] printing files > Just a quick question, > is there a way to echo in your php code lines of a file that you specify. > i.e. you want to output lines 1,4,7 of a certain text file > Thanks > John > > > > _ > Join the world's largest e-mail service with MSN Hotmail. > http://www.hotmail.com > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php