Jump to content


Photo

valadation problam concept cheers.


  • Please log in to reply
3 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 September 2006 - 09:09 PM

This example the foreach does only ouput the > correctly but when i use in the $mess < get nothink.
<?php
$mess="hi there < hows you";

$not_allowed=array("<",">");

foreach($not_allowed AS $key => $val){

if(eregi($key,$mess)){

echo "word bad";
exit;

}else{

echo "word ok";
exit;
}
 }
?>

This code i get nothink on the screen.
<?php
$mess="hi there < hows you";

$not_allowed=array("<",">");

for($i=0; $i<count($not_allowed); $i++){

if(eregi($key,$mess)){

echo "word bad";
exit;

}else{

echo "word ok";
exit;
}
 }
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 13 September 2006 - 09:15 PM

For your first code snipped you'll wnat to use $val rather than $key in your if statement so the code should be this:
<?php

$mess = "hi there < hows you";

$not_allowed = array("<", ">");

foreach($not_allowed as $val)
{
    if(eregi($val, $mess))
    {
        echo "word bad";
        exit;
    }
    else
    {
        echo "word ok";
        exit;
    }
}

?>
However havn't we goine over this subject many times before? I can recall you posting something similar to this before

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 September 2006 - 09:23 PM

i am getting words ok why?

thank you for your help cheers i no we went over this before but im getting strange results.

<?php

$mess = "hi there > hows you";

$not_allowed = array("<", ">");

foreach($not_allowed as $val)
{
    if(eregi($val, $mess))
    {
        echo "word bad";
        exit;
    }
    else
    {
        echo "word ok";
        exit;
    }
}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 13 September 2006 - 09:34 PM

Because you are using exit on the if/else statement. When you use exit is stops the script from running. So if < was not found in the string the script would exit and print word ok. However if > was found it'll exit and show word bad. If you remove the exit; it'll print word okword bad.

You dont to use exit in the if/else statement otherwise it wont complete the loop. It'll only run once.

Prehaps you want to do something like this:
$mess = "hi there > hows you";

$not_allowed = array("<", ">");

foreach($not_allowed as $val)
{
    if(eregi($val, $mess))
    {
        echo "We have detected a word/symbol(s) that we do not accept. Please do not use any of the words/symbols below:<br />\n";

        echo 'Words/Sybols not allowed: ' . implode(", ", $not_allowed);
    }
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users