'generated HTML table from a text file with PHP. End of file is displayed as a table entry. How can I prevent this?

I found here the solution. The problem is that the script also sees the end of file as an entry and displays it as an empty line in the table.

Print screen of the output

Content of the text file:

Select browser|select_browser.pdf|comment of the file|PDF|03.03.2022
Print document|print_document.pdf|comment of the file|PDF|01.01.2022

PHP script:

<?php
 # https://stackoverflow.com/questions/29867025/create-table-from-text-file-using-php
 $file = fopen("info.txt", "r") or die("Unable to open file!");
 while (!feof($file)) {
  $data = fgets($file); 
  list($filename, $linktext, $comment, $filetype, $datetime) = explode("|", $data);
?> 

 <tr>
  <td><a href="<?=$filename ?>"><?=$linktext ?></a></td>
  <td><?=$comment ?></td>
  <td style="text-align: right;"><?=$filetype ?></td>
  <td style="text-align: right;"><?=$datetime ?></td>
 </tr>

<?php
 }
 fclose($failas);
?>

How can I prevent this? I thank you for your help!



Solution 1:[1]

According to the documentation of 'textlocal' here: https://www.textlocal.in/free-developer-sms-api/

The only required field you need to pass towards the API are:

  1. apikey [provided by textlocal]
  2. numbers [destination numbers]
  3. sender
  4. message

There is no 'apikey' in your parameter "$data", but only field that the API doesnot accepts, ie. username and password.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vicky Maharjan