Jump to content

return question


adv

Recommended Posts

<?php

$message = "this is my test, of bad words";
$foundBadWord = filter($message);
if($foundBadWord)
{
header("Location: ban.php");
exit;
}

echo $message;


function filter($message)
{
//Get contents from file
$Ban = file_get_contents ("filter.txt");

//Get contents from string(for testing)
#$Ban = "tests\ntesting";

//put into a array
$BanWords = explode("\n",$Ban);
foreach($BanWords as $B)
{
	//check for bad word
	if (strpos($message,$B))
	{
		//found one
		return false;
	}
}
//none found
return true;
}
?>

i saw this on this forum but the topic was solved

but i have a question

 

<?php
foreach($BanWords as $B)
{
	//check for bad word
	if (strpos($message,$B))
	{
		//found one
		return false;
	}
}
//none found
return true;
?>

why does foreach return true if nothing is found .. it shouldn`t return false; ??

 

if (strpos($message,$B))

{

//found one

return false;

}

 

why does it returns false

because  this (strpos($message,$B))  is true .. it shouldn`t  return true; ??

 

 

Link to comment
https://forums.phpfreaks.com/topic/104697-return-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.