flobeats Posted May 29, 2007 Share Posted May 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/53478-read-from-a-file-line-by-line/ Share on other sites More sharing options...
trq Posted May 29, 2007 Share Posted May 29, 2007 You'll need to write each line of the file into a Javascript array at page load, then use Javascript to write each line to the screen. Quote Link to comment https://forums.phpfreaks.com/topic/53478-read-from-a-file-line-by-line/#findComment-264341 Share on other sites More sharing options...
chigley Posted May 30, 2007 Share Posted May 30, 2007 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53478-read-from-a-file-line-by-line/#findComment-264569 Share on other sites More sharing options...
mogs Posted May 30, 2007 Share Posted May 30, 2007 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). Quote Link to comment https://forums.phpfreaks.com/topic/53478-read-from-a-file-line-by-line/#findComment-264927 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.