Wrong parameter count for strstr()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Wrong parameter count for strstr()

Post 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);						
}
?>
Last edited by Kriek on Fri Dec 13, 2002 8:09 pm, edited 9 times in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

I'd like to check $ref for $dig and $dom
It's basically going to exclude them from the results.
Last edited by Kriek on Thu Dec 12, 2002 11:10 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

Thanks! That worked perfect.
I'll remember that next time.
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post by nathus »

could also use ereg("($dig|$dom)", $ref)
Post Reply