Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2007
    Posts
    1

    Unanswered: How to read HTML or TXT file and output the data?

    Does anyone know if this is possible?
    Script reads a HTML file or a TXT file and output the data to MySQL database.

  2. #2
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    I think you mean "input" TO a MySQL database. You "output" FROM a MySQL database.

    Code:
    $data = "";
    $filename = "myfile.txt";
    $fh = fopen($filename,'r');
      while (!feof($fh)) {
        $data .= fread($fh, 8192);
      }
    fclose($fh);
    
    $hostname = "db.myhost.com";
    $username = "myuser";
    $password = "mypass";
    $database = "mydb";
    $conn = mysql_connect($hostname,$username,$password);
    mysql_select_db($database,$conn);
    mysql_query("INSERT INTO <table>(field1) VALUES('{$data}')",$conn);
    Last edited by aschk; 04-23-07 at 07:55.

Posting Permissions

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