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? Link to comment https://forums.phpfreaks.com/topic/229849-echo-lines-from-text-file/ 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 Link to comment https://forums.phpfreaks.com/topic/229849-echo-lines-from-text-file/#findComment-1183872 Share on other sites More sharing options...
Scummy12 Posted March 7, 2011 Author Share Posted March 7, 2011 Exactly what I wanted, thank you Link to comment https://forums.phpfreaks.com/topic/229849-echo-lines-from-text-file/#findComment-1183877 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.