Page 1 of 1

Wrong parameter count for strstr()

Posted: Thu Dec 12, 2002 11:00 pm
by Kriek
Ok this is driving me nuts.

Wrong parameter count for strstr() on line 8

Code: Select all

<?php
$log = 'log.txt';
$exit = 'exit.ref';
$max = 20;
$dom = 'home.com';
$dig = 'something.net';
$ref = getenv("HTTP_REFERER");
if (($ref) and (!strstr($ref, $dig, $dom))) {	
	$ref .= "\n";								
	$sp = fopen($exit, "w");				
	if (flock($sp, 2)) {						
		$rfile = file($log);	
		if ($ref <> $rfile[0]) {				
			if (count($rfile) == $max)		
				array_pop($rfile);				
			array_unshift($rfile, $ref);		
			$r = join("", $rfile);				
			$rp = fopen($flog, "w");			
			$status = fwrite($rp, $r);			
			$status = fclose($rp);				
		}
	}
	$status = fclose($sp);						
}
?>

Posted: Thu Dec 12, 2002 11:04 pm
by volka
http://www.php.net/manual/en/function.strstr.php
string strstr ( string haystack, string needle)

Code: Select all

strstr($ref, $dig, $dom)
the parser is absolutly right about this ;)
What do you want to achieve? testing wether $ref contains $dig or $dom?

Posted: Thu Dec 12, 2002 11:08 pm
by Kriek
I'd like to check $ref for $dig and $dom
It's basically going to exclude them from the results.

Posted: Thu Dec 12, 2002 11:10 pm
by volka
strstr cant do it.
You might use preg_match as it can take an array of patterns. But they are tested sequencly (?).

Code: Select all

!strstr($ref, $dom) and !strstr($ref, $dig)
will do.

Posted: Thu Dec 12, 2002 11:18 pm
by Kriek
Thanks! That worked perfect.
I'll remember that next time.

Posted: Thu Dec 12, 2002 11:30 pm
by nathus
could also use ereg("($dig|$dom)", $ref)