Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-31-2007, 05:30 PM   PM User | #1
eon201
New Coder

 
Join Date: Oct 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
eon201 is an unknown quantity at this point
Lightbulb Using File handling, and time manipulation within lines

Hi,

Ive come across something that i just dont know how to approach.
Basically I have two pages of php.

Page 1 creates a file with lines of data, each line of data looks like this:
Code:
Please call MrSmith immediately. On telephone number 02392666666. Thank you.1615
Now what I need to do with this data is take the last 4 digits of the strings (which are individual stamps of time etc 4:15pm) and work out:
1.How many lines appearred within the last hour.
2.If the last line is new (which would only be true if the time stamp on the line is equal to the current one of date('Gis').

Here is how far I have come so far. Any help would be greatly appreciatted.
Code:
<?php 
$filename = 'phonecsv/'. date('ymd'). '.csv';

	if (file_exists($filename)) 
	{
		$fp = fopen($filename, "r");
	
		// works out how many callback requests today
		$lines = count(file($filename));
		echo "Today there have been $lines callback requests <br/>";
		
		// needs to work out from time sequence how many in last hour
		echo "In the last hour there have been x callback requests<br/>";
		
		// needs to work out from time sequence if new message
		echo "This is the latest callback request<br/>";
		
		$data = fgets($fp);		
	}
	
	else
	{
    	echo "The file $filename does not exist!! Check the svr file and callback forwarder!<br/>";
	}
?>
<!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>
</head>

<body>
<?php
	echo $data;
?>

<script type="text/javascript">
// set the page to reload every 20 sec
setTimeout('window.location.href = '<?php echo $_SERVER['php_self']; ?>', 20);
</script>
</body>
</html>
Thanks. eon201.
eon201 is offline   Reply With Quote
Old 10-31-2007, 09:16 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
The mktime() function will convert your time to a unix timestamp. You'll want to add the current date to the string. Then get the current unix timestamp (once again mktime() can make that happen) and subtract 3600 from it (there are 3600 seconds in an hour). If your record's unix timestamp is >= the current unix timestamp, it happened in the last hour.

This is kind of a shoddy solution because it does not account for the midnight crossover when 2359 becomes 0000. It appears you create a new file for each day though so maybe that's not an issue for you. If it is... then I'd store a full unix timestamp in your file rather than a 4-digit time.

To get the most recent I would dump all the time strings into an array and sort the array desc.
__________________
Fumigator is offline   Reply With Quote
Old 11-01-2007, 09:56 AM   PM User | #3
eon201
New Coder

 
Join Date: Oct 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
eon201 is an unknown quantity at this point
Hi,

Thanks for the response. The only problem is I am quite a noob. Any chance you can show me an example??

Thanks. Eon201
eon201 is offline   Reply With Quote
Old 11-01-2007, 04:11 PM   PM User | #4
aedrin
Senior Coder

 
Join Date: Jan 2007
Posts: 1,648
Thanks: 1
Thanked 58 Times in 54 Posts
aedrin will become famous soon enough
Example: Consider using a database.
aedrin is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:14 AM.


Advertisement
Log in to turn off these ads.