<?php
echo "<html><title>Preview Article</title>
<body bgcolor=\"#FFFFFF\" link=\"#0000FF\" vlink=\"#0000FF\" alink=\"#0000FF\">\n";

function mk_txt_line_array($buf) {
    $lnarray = split("\n", $buf);

  return $lnarray;
}

$search = array ("'<script[^>]*?>.*?</script>'si",  // Strip out javascript
                 "'<[/!]*?[^<>]*?>'si",          // Strip out HTML tags
                 //"'([rn])[s]+'",                // Strip out white space
                 "'&(quot|#34);'i",                // Replace HTML entities
                 "'&(amp|#38);'i",
                 "'&(lt|#60);'i",
                 "'&(gt|#62);'i",
                 "'&(nbsp|#160);'i",
                 "'&(iexcl|#161);'i",
                 "'&(cent|#162);'i",
                 "'&(pound|#163);'i",
                 "'&(copy|#169);'i",
                 "'&#(d+);'e");                    // evaluate as php

$replace = array ("",
                 "",
                 //"\1",
                 "\"",
                 "&",
                 "<",
                 ">",
                 " ",
                 chr(161),
                 chr(162),
                 chr(163),
                 chr(169),
                 "chr(\1)");

$artpth = $_REQUEST['file'];

$fp = fopen($artpth, "r");
$buf = fread($fp, filesize($artpth));
fclose($fp);

$buf = stripslashes($buf);
$file_ext = substr(strrchr($artpth, '.'), 1);

if($file_ext == "txt") {
	$buf = str_replace("\n", "<br>", trim($buf));
}

echo $buf;

/*
$file_ext = substr(strrchr($artpth, '.'), 1);

if($file_ext == "htm" or $file_ext == "html") {

$fntext = preg_replace('/<a (.+?)>(.+?)<\/a>/is', '[a] \1>\2[/a]', $buf);

$fntext = preg_replace($search, $replace, $fntext);

$resultln = mk_txt_line_array(trim($fntext));

$txttitle = trim($resultln[0]);

if($txttitle == "\r"){
$txttitle = trim($resultln[1]);
}

$txtdescription = str_replace($txttitle, "", trim($fntext));

$txttitle = preg_replace($search, $replace, $txttitle); //must be after $txtdescription

$txtdescription = str_replace("[a]", "<a ", trim($txtdescription));
$txtdescription = str_replace("[/a]", "</a>", trim($txtdescription));
$txtdescription = str_replace("\n", "<br>", trim($txtdescription));
$txtdescription = str_replace("’", "'", trim($txtdescription));
$txtdescription = str_replace("“", "\"", trim($txtdescription));
$txtdescription = str_replace("”", "\"", trim($txtdescription));
$txtdescription = str_replace("–", "-", trim($txtdescription));
//$txtdescription = htmlentities(trim($txtdescription));

echo "<b>Title: " . trim($txttitle) . "</b><br>";
echo "<br>" . trim($txtdescription);
}

if($file_ext == "txt") {

$resultln = mk_txt_line_array(trim($buf));

$txttitle = trim($resultln[0]);

if($txttitle == "\r"){
$txttitle = trim($resultln[1]);
}

$txtdescription = str_replace($txttitle, "", trim($buf));

$txtdescription = str_replace("\n", "<br>", trim($txtdescription));
$txtdescription = str_replace("’", "'", trim($txtdescription));
$txtdescription = str_replace("“", "\"", trim($txtdescription));
$txtdescription = str_replace("”", "\"", trim($txtdescription));
$txtdescription = str_replace("–", "-", trim($txtdescription));
//$txtdescription = htmlentities(trim($txtdescription));

$txttitle = preg_replace($search, $replace, $txttitle); //must be after $txtdescription
echo "<b>Title: " . trim($txttitle) . "</b><br>";
echo "<br>" . trim($txtdescription);
}
*/
?>

<br><br><br>
<center><script language="JavaScript">
<!--
document.write('<a href="javascript:self.close()">Close this window</a><br>');
// -->
</script>
</center>
</body>

</html>