Search code examples
phphtmlfilefopentxt

How to open make hyperlink for txt files


I created 3 text files and I want to create a bullet form list with hyperlinks that will direct the user to each file created. How can I code this?

echo "<ul>";
echo "<li>" . <a fopen("test.txt", "r") or die("Unable to open file!");>Test 1</a>  "</li>";
echo "<li>"  . $filename = 'test2.txt' . "</li>";
echo "/<ul>";

Solution

  • Please note that /<ul> is not the correct closing tag, it should be </ul>

    On the other hand, you may use the Nowdoc string quoting syntax (or similar):

    <?php
    echo <<<'EOD'
    
    <ul>
    <li><a href='test.txt'>Test1</a></li>
    <li><a href='test2.txt'>Test2</a></li>
    </ul>
    
    EOD;
    
    ?>
    

    For further reference on the above , please view the official documentation:

    http://docs.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc