# Printing just the top 5 lines \[PHP\]

**URL:** <https://forum.kirupa.com/t/printing-just-the-top-5-lines-php/141369>\
**Category:** Uncategorized\
**Created:** [March 19, 2005, 10:01am UTC](https://forum.kirupa.com/t/printing-just-the-top-5-lines-php/141369 "2005-03-19T10:01:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveMania](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@DaveMania](https://forum.kirupa.com/u/DaveMania)\
**Post date:** [March 19, 2005, 10:01am UTC](https://forum.kirupa.com/t/printing-just-the-top-5-lines-php/141369/1 "2005-03-19T10:01:17Z")

</div>

```php

<?php
$fp = fopen('db.php','r');
if (!$fp) {echo 'ERROR: Unable to open file.'; exit;}

while (!feof($fp)) {
$line = fgets($fp, 1000);
list ($field1, $field2, $field3, $field4, $field5, $field6) = split ('\|', $line);
echo '

<tr>
<td>'.$field1.'</td>
</tr>';
$fp++;
}
 
fclose($fp);
 
?>

```

How can i makes it so that $line only selects the top 5 lines?
