KrisGeor KrisGeor - 1 month ago 21
HTML Question

How to get string from a file using php

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

Answer Source

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.