I a'm having a nightmare!!

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
icarpenter
Forum Commoner
Posts: 84
Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England

I a'm having a nightmare!!

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

#^\s*video.*$(?s:\s*)^\s*(\d+)\s*$#im
maybe
User avatar
icarpenter
Forum Commoner
Posts: 84
Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England

Post 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...
Post Reply