Working on a project, one of the webpages will display a list of people (specifically, a list of people from a graduation class that haven\'t been located yet). Instead of m
That's the code I use:
<?php
$path="C:/foopath/";
$file="foofile.txt";
//read file contents
$content="
<h2>$file</h2>
<code>
<pre>".htmlspecialchars(file_get_contents("$path/$file"))."</pre>
</code>";
//display
echo $content;
?>
Keep in mind that if the user can modify $path or $file (for example via $_GET or $_POST), he/she will be able to see all your source files (danger!)
Easy way:
missingmen.txt
to missingmen.html
.missingmen.html
:<link href="txtstyle.css" rel="stylesheet" type="text/css" />
txtstyle.css
, and add to it a line like this:html, body {font-family:Helvetica, Arial, sans-serif}
In more recent browsers code like below may be enough.
<object data="https://www.w3.org/TR/PNG/iso_8859-1.txt" width="300" height="200">
Not supported
</object>
You can add it as script file. save the txt file with js suffix
in the head section add
<script src="fileName.js"></script>
You cannot style a text file, it must be HTML
If you just want to throw the contents of the file onto the screen you can try using PHP.
<?php
$myfilename = "mytextfile.txt";
if(file_exists($myfilename)){
echo file_get_contents($myfilename);
}
?>