File Manipulation Code

  Home arrow File Manipulation Code arrow Simple CSV to HTML Table
FILE MANIPULATION CODE

Simple CSV to HTML Table
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 10
    2003-04-14

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    Gets a specified Comma Seperated file from the variable $filename and displays as a simple html table.

    By : Rock

    <?php
    /*/-------------------------------------------------------------------\
    | Original Name : csvview.php |
    | Author : Neil Maskell |
    | Function : Reads a specified CSV file (Comma seperated) and |
    | converts it into a readable HTML table. |
    | |
    | You could set up a html form with an input field |
    | called filename. Then use csvview.php as the action. |
    | |
    | the reason cache is being disabled is because if you |
    | update the csv file the cache doesnt realise and shows|
    | an older version of the information. |
    | |
    | The CSV files should (and normally are) in the format:|
    | field1,field2,filed3,filed4 |
    | field1,field2,field3,field4 |
    \-------------------------------------------------------------------/

    */
    //
    $filename = ""; // File to open. quote out this variable if you are using a form to link to this script.


    /*
    No cache!!
    */
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    // always modified
    header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache"); // HTTP/1.0
    /*
    End of No cache
    */




    function viewlog($filename) {
    $fp = fopen($filename,"r");
    $file = fread($fp,65535);
    $replaced = eregi_replace(",", "<td>", $file);
    $replaced2 = eregi_replace("\n", "<tr><td>", $replaced);
    $replaced3 = eregi_replace("\r", "<tr><td>", $replaced2);
    fclose($fp);

    return $replaced3;
    }
    echo "<html><head><base href=\"./\"><title>CSV File Viewer</title></head><body bgcolor=silver>";
    // Start the table definition of your choice
    echo "<table border=0 bordercolor=black cellspacing=0 cellpadding=5 width=100% style='font-size:10pt'>";

    echo viewlog($filename);
    echo "</table></body></html>";
    exit;
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More File Manipulation Code Articles
    More By Codewalkers

    blog comments powered by Disqus
    Antalya eskort Antalya escort bayanlar izmir escort

    FILE MANIPULATION CODE ARTICLES

    - Bandwidth Control with pure PHP
    - Eazy Gallery
    - file_get_contents for PHP < 4.3.0
    - PHP Class: Image Snapshot 1.3
    - Universal downloader
    - Image Gallery v2.0
    - Free/Used Disk Space
    - Directory Lister
    - Directory image view, with selective hidden
    - Move or Copy a Directory (and files and sub ...
    - Ensure_Sub_Directory_Exists
    - Wedit
    - Form Examples Text Boxes to Drop Downs
    - myFiles
    - List files in a directory, no subdirectories

    Developer Shed Affiliates

     



    © 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap