Page 1 of 1

I a'm having a nightmare!!

Posted: Thu Mar 09, 2006 12:26 pm
by icarpenter
Can anyone help I have come up against a brick wall...

I am opening the http port of a device and would like to filter out some data that is returned. but my regex commands arn't doing what I want...it seems to go a little weird arround the carriage return and new line...

Code: Select all

$pattern = '^(Video buffer underflows \(this connection\)\r\n1)^';

$connection = fopen("http://" .$IP. "/index.htm", "r");
	if ($connection) {
	   while (!feof($connection)) {
	       $buffer = fgetss($connection, 4096);
		$buffer = rtrim($buffer);
		preg_match($pattern, $buffer, $match);
		//echo $buffer;
		print_r($match);		
	   }
	fclose($test);
	}
This is the output of the variable $buffer when I echo this...I then do a view source but I cant get find the pattern..

Video buffer underflows (this connection)
1

Ideally what I am after is the value '1' in a variable, this number could go as high as100000...

Code: Select all

Video buffer overflows (this connection)
0


Video buffer underflows (this connection)
1


Audio continuity errors (this connection)
0
Can anyone help...

Many Thanks Ian[/quote]

Posted: Thu Mar 09, 2006 1:00 pm
by feyd

Code: Select all

#^\s*video.*$(?s:\s*)^\s*(\d+)\s*$#im
maybe

Posted: Fri Mar 10, 2006 8:47 am
by icarpenter
Thanks Fayed...

I got it in the end by doing...

Code: Select all

fopen("http://" .$IP. "/index.htm", "r");
	$connection = fopen("http://" .$IP. "/index.htm", "r");
	$test1  = array('0','0');
		$i=0;
			if ($connection) {
			   while (!feof($connection)) {
			       	$buffer = fgetss($connection, 60);
				$test1[$i] = $buffer;
				$i++;
			   }

			   ?><table border=1><tr><?
			   echo "<td width=300>" . $test1[105] . "</td><td width=100 color=#fffff>" . $test1[106] . "</td>";
			   ?></tr></table><?
Thanks Ian...