Page 1 of 1

foreach always returns true/false?

Posted: Sun Mar 18, 2007 11:31 pm
by JAB Creations
This somewhat simple script is supposed to detect (X)HTML validators and allow cloaking to compensate for errors in web standards. However it's always returns true or false (not sure which it is).

Code: Select all

<?php
$useragent = $_SERVER['HTTP_USER_AGENT'];
$validator = array(
'W3C_Validator',
'WDG_Validator',
);

foreach ($validator as $ua) {
 if (stristr($validator,$ua)) { 
  $result = TRUE;
  break;
 }else{
  $result = FALSE;
 }
}

if(!$result)
{echo 'not result';}
else
{echo 'result';}

echo '<br />' . $useragent;
?>

Re: foreach always returns true/false?

Posted: Sun Mar 18, 2007 11:37 pm
by Christopher

Code: Select all

<?php
$useragent = $_SERVER['HTTP_USER_AGENT'];
$validator = array(
'W3C_Validator',
'WDG_Validator',
);

$result = FALSE;
foreach ($validator as $ua) {
 if (stristr($useragent,$ua)) { 
  $result = TRUE;
  break;
 }
}

if(!$result)
{echo 'not result';}
else
{echo 'result';}

echo '<br />' . $useragent;
?>

Posted: Sun Mar 18, 2007 11:40 pm
by JAB Creations
Oh cool, thanks! They need to post more examples at php.net.