Hi Folks,
Well another day another php.
What I have is a php script that displays a text file (stored in the $filedata variable),...
<?
$filedata = '';
if ( $fh = fopen( "menulist.txt", "r" ) )
{
while ( $buffer = fread( $fh, 4096 ) )
{
$filedata .= $buffer;
}
}
else
{
print "Oops.. couldn't open file";
}
?>
<table>
<tr>
<td><?= nl2br( $filedata ) ?></td>
</tr>
</table>
</body>
Easy enough - it works with text or html. I found a snippet of code that allows me to, say, take a (crappy) MSWORD html doc and strip all the aforementioned "crap" out of it. However, am I correct in assuming the $text variable below should be mapped to the $filedata variable?
function cleanUpHTML($text) {
// remove escape slashes
$text = stripslashes($text);
// trim everything before the body tag right away, leaving possibility for body attributes
$text = stristr( $text, "<body");
// strip tags, still leaving attributes, second variable is allowable tags
$text = strip_tags($text, '<p><b><i><u><a><h1><h2><h3><h4><h4><h5> <h6>');
// removes the attributes for allowed tags, use separate replace for heading tags since a
// heading tag is two characters
$text = ereg_replace("<([p|b|i|u])[^>]*>", "<\\1>", $text);
$text = ereg_replace("<([h1|h2|h3|h4|h5|h6][1-6])[^>]*>", "<\\1>", $text);
return ($text);
}
?>
I appreciate your help.
Thanks.


LinkBack URL
About LinkBacks



Reply With Quote
Bookmarks