-1

Ok so I have a txt file (mytxt.txt)

Content inside is saved like this

name (username)
name (username)

And I'm trying to get these lines and put them in a HTML <li> element but I can't figure out how

What im trying to do is to get every line of the document to echo in a difrent <li> HTML element

KrisGeor
  • 53
  • 1
  • 6
  • 1
    Here is a link to the [PHP Manual, filesystem section](http://php.net/manual/en/ref.filesystem.php) The manual is always a good place to start – RiggsFolly Aug 24 '17 at 00:26
  • Use the `file()` function to read a file into an array of strings. Each line is an element. – Barmar Aug 24 '17 at 00:33
  • Possible duplicate of [How to read a file line by line in php](https://stackoverflow.com/questions/13246597/how-to-read-a-file-line-by-line-in-php) – Charles Aug 24 '17 at 01:54

1 Answers1

2

You can read a file with php like this:

<?php
$myfile = fopen("mytxt.txt", "r") or die("Unable to open file!");
while( !feof( $myfile ) ) {
?> <li> <?php echo fgets($myfile); ?> </li>
<?php
}

fclose($myfile);
?>

just place this inside the element that you want the info to echo into.

Mr.Lister
  • 422
  • 3
  • 11
  • 1
    If that worked for you can you please mark as answer? – Mr.Lister Aug 24 '17 at 01:17