Re: No Idea - Comparing Lines

From: Date: Mon, 06 Jan 2003 18:53:14 +0000
Subject: Re: No Idea - Comparing Lines
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-130477@lists.php.net to get a copy of this message
Hi Chris-- Try this: <?php $lines = file ('test.txt'); $i = 0; while ($i < count ($lines)) { preg_replace ('/([^|]*):([^|]*)|/e', '$data["$1"] = "$2"', $lines[$i]); if ($i > 0) { $kbitsout = ((((float) $data['OctetsOut'] - $olddata['OctetsOut']) / ($data['UnixTime'] - $olddata['UnixTime'])) * 8 ) / 1000; print str_pad ($i, 2, ' ', STR_PAD_LEFT) . ' -- ' . number_format ($kbitsout, 2) . " kbits/s\n"; } $olddata = $data; $i++; } ?> I suggest you add some code to check for divisions by zero, depending on whether your data requires it! Cheers, Marco -- ---------------- php|architect - The Monthly Magazine for PHP Professionals Come check us out on the web at http://www.phparch.com!

« previous php.general (#130477) next »