Scummy12 Posted March 7, 2011 Share Posted March 7, 2011 I have a .txt file containing hundreds of lines of Names (e.g. Brad, Jennifer, etc.) What coding can I use to only echo the first 20? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 7, 2011 Share Posted March 7, 2011 Read the file into an array and echo the first 20 lines: <?php $x = file('yourfile.txt'); $limit = (count($x) > 20)?20:count($x); for ($i=0;$i<$limit;++$i) { echo nl2br($x[$i]); } ?> Ken Quote Link to comment Share on other sites More sharing options...
Scummy12 Posted March 7, 2011 Author Share Posted March 7, 2011 Exactly what I wanted, thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.