Đăng Nhập

Vui lòng khai báo chính xác tên truy cập và mật khẩu!

Quên mật khẩu?

    Code đọc file txt

      Admin
      Admin

      Giới tính : Nam

      Đến từ : TPHCM

      Ngày Tham gia : 03/04/2011

      Tổng số bài gửi : 2292

      #1

       Tue Mar 27, 2012 5:43 pm

      code doc file text

      Code:

       var allText =[];
         var allTextLines = [];
         var Lines = [];
         var txtFile = new XMLHttpRequest();
         
         txtFile.open("GET", "file://D:/text_file.txt", true);
         allText = txtFile.responseText;
         //allTextLines = allText.split(/\r\n|\n/);
         //alert(allTextLines);
         txtFile.onreadystatechange = function()
         {
            if (txtFile.readyState == 4)
            {
               
                    // Makes sure it's found the file.
                      allText = txtFile.responseText;
                     allTextLines = allText.split(/\r\n|\n/);
                  
                     document.write(allText);
                  } else {
                                  alert("Khong hoat dong");
                  }
            
            }
         txtFile.send(null)


      Code:
      <?php
      $content = file_get_contents('text_file.txt');
      ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled Document</title>
      <script type="text/javascript">
          var some_var = '<?php echo $content?>';
          window.onload = function() {
              document.getElementById('content').innerHTML = some_var;
          }
      </script>
      </head>
      <body>
      <div id="content"></div>
      </body>
      </html>