LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-27-2005, 01:12 PM   #1
mrobertson
Member
 
Registered: May 2005
Posts: 275

Rep: Reputation: 30
Printing numbers from a text file dynamically


I was wondering if anyone could help me with a problem that I am having. I have a vb6 client that generates numbers every second. Those numbers are printed to a text file ...each new number replacing the old number. I need to write a php script that reads and display these numbers. I am sure that this is not a hard task but I am new at php and am looking for some guidance. I originally wrote a script using sockets and later found that network camera that will run this script does not support sockets. Here is the socket code that I used:

Code:
<?php
$read_write = "read";

if ($read_write == "read") {
	//Initialize the socket
	set_time_limit(0);
	$address = '127.0.0.1';
	$port = 10119;

	if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
		echo "socket_create() failed. Reason: " . socket_strerror($sock) . "<BR>";
	}

	if (($ret = socket_bind($sock, $address, $port)) < 0) {
		echo "socket_bind() failed. Reason: " . socket_strerror($ret) . "<BR>";
	}

	//Start listening on the socket
	if (($ret = socket_listen($sock, 5)) < 0) {
		echo "socket_listen() failed. Reason: " . socket_strerror($ret) . "<BR>";
	}

	//Accept an incoming connection
	if(($client = socket_accept($sock)) < 0) {
		echo "socket_accept() failed. Reason: " . socket_strerror($ret) . "<BR>";
		break;
	}

	//Read whatever was just sent, 1024 bytes' worth. Make this however long you need.
	if( false == ($global_string = socket_read($client, 2048))) {
		echo "socket_read() failed. Reason: " . socket_strerror($ret) . "<BR>";
		break;
	}

	//Strip whitespace
	$global_string = ereg_replace("[ \t\n\r]", "", $global_string).chr(0);

	$array = explode(',', $global_string);

	print ("Global string before being parsed: $global_string\n<BR>");
	print ("Global string after being parsed:<BR>");

	$id = $array[0];
	$width = $array[1];
	$footagecount = $array[2];
	$length = $array[3];

	print("<BR>");
	print ("Serving Client!<BR>");

	//print("<textarea wrap='OFF'>$id</textarea>";

	print("Coil ID number: $id<BR>");
	print("Coil Width: $width<BR>");
	print("Footage Count: $footagecount<BR>");
	print("Coil Length: $length<BR>");

	//Close the connection; Don't leave things like this open...!!
	socket_close($client);

	//Close the socket itself
	socket_close($sock);
} //ends if ("read")

if (isset($_GET['counter'])) {
	$counter = $_GET['counter'];
} else {
	$counter = 0;
}

$counter++;

echo "just testing... " . $counter . "<br>";

$redirect_page = $_SERVER['PHP_SELF'] . "?counter=" . $counter;
?>

<script language="javascript">
setTimeout("window.location = '<? echo $redirect_page; ?>'", 1000);
</script>

As you can see I redirect the page so that it refreshes.  I may be able to use my redirectpage function and the small area of javascript that I already have.  I just need to know how to read from a text file and print whatever it reads out.  Also would it be easier to read separate lines or one line with all of the values?Can anyone help me with this?
 
Old 06-28-2005, 08:19 AM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Moved: More suitable in Programming.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reading and printing out a text file in html mrobertson Programming 1 07-08-2005 11:47 PM
printing numbers without using semicolon vijeesh_ep Programming 18 09-08-2004 11:59 AM
printing line numbers? fisheromen1031 Programming 1 07-27-2004 02:19 PM
Complicated Text -> Numbers mickey717 Linux - Newbie 5 10-17-2003 01:41 PM
Compressing a file dynamically xanthium Programming 5 03-22-2002 05:06 PM


All times are GMT -5. The time now is 11:50 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration