Jump to content

Recommended Posts

Hy, I have a question..I want to do a demo page to simulate the read of the temperature from a room. I want to do that read from a file.txt. In this file i write data manualy:

18 celsius or just 18

19

20

19

21

...

I want to show this data in my page. php row by row in 30 seconds. First 18, after 30 seconds 19, after 30 sec 20...Enybody have ideeas how cold i do that?

Thanks.

 

 

Link to comment
https://forums.phpfreaks.com/topic/53478-read-from-a-file-line-by-line/
Share on other sites

Javascript isn't my thing, but I can show you how to get a JS array with the values in:

 

<?php

$lines = file("file.txt");

echo "<script type=\"text/javascript\">\nvar temperatures = new Array()\n";

foreach($lines as $number => $temp) {
echo "temperatures[$number] = $temp\n";
}

echo "</script>";

?>

Check out combining 'prototype' (a javascript library) using the AJAX.Request or AJAX.Updater function with your PHP file (if you actually need to use PHP in the first place). Here's a good reference: http://www.sergiopereira.com/articles/prototype.js.html. If you are just reading it from a text file however, you won't need PHP as javascript can access text files directly (i think).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.