Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 3 of 3

This is a discussion on Display ms word as html in the Shared & Semi-Dedicated forum
Hi Folks, Well another day another php. What I have is a php script that displays a text file (stored in the $filedata variable),... <? ...

  1. #1
    JPC Member
    Join Date
    Jan 2003
    Posts
    9

    Display ms word as html

    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.

  2. #2
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    Yes, you are correct. You would call it like this:

    $cleanned = cleanUpHTML($filedata);

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  3. #3
    JPC Member
    Join Date
    Jan 2003
    Posts
    9

    DOH! That's right!!

    That's what I thought, it was the call that threw me a bit - I'm not as stupid as I thought,..or maybe I am, I dunno, but thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •