# \[php\] giving me a headache - IF and WHILE function

**URL:** <https://forum.kirupa.com/t/php-giving-me-a-headache-if-and-while-function/142513>\
**Category:** Uncategorized\
**Created:** [March 29, 2005, 1:35pm UTC](https://forum.kirupa.com/t/php-giving-me-a-headache-if-and-while-function/142513 "2005-03-29T13:35:43Z")\
**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 29, 2005, 1:35pm UTC](https://forum.kirupa.com/t/php-giving-me-a-headache-if-and-while-function/142513/1 "2005-03-29T13:35:43Z")

</div>

I have a code at the moment that prints all the lines from a text document and sparates the with delimeters.

```php
$fp = fopen('TEXT_FILE','r');
if (!$fp) {echo 'File Doesn\'t Exist'; exit;}

while (!feof($fp)) {
$line = fgets($fp, 1024);
list ($field1, $field2, $field3) = split ('\|', $line);
echo '
<p>'.$field1.'</p>
<p>'.$field2.'</p>
<p>'.$field3.'</p>
</div>
';
++$fp;
}
fclose($fp);

```

Can someone tell me how to make it so that it only loops a certain number of times (say $max amount of times) and thus only displaying the first $max number of lines?

I’ve tried several different methods myself, all of which don’t work
