read a line from a file

By cooolstar on Jun 01, 2005

its just for php beginners.
simple it read a line from path read/new.txt ( a filemay be .txt or any extension).

world cooolstar Pakistan
cooolstar@gmail.com

<?php
$linenum = 2; //will read 2nd line of the file.
$path = "read/new.txt";
$handle = fopen($path, "r");
$lines=file($path); //$lines is an array 
echo htmlentities($lines[$linenum]);
?>

Comments

Sign in to comment.
m40295   -  Jun 09, 2012

is there a mirc ver of this as i am trying to do the same thing

 Respond  
Hawkee   -  Nov 02, 2005

Kutsum, you can use the above code and simply do count($lines) to find the number of lines in the array.

 Respond  
KuTsuM   -  Oct 08, 2005

how do you find how many lines there are total in a file?

 Respond  
Rower   -  Jun 01, 2005

so why is this usefull?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.