How do you put a variable in the ereg string validation?

I know that
ereg("[a-z]$", $variable_to_find_it_in)

will return a lowercase alphanumeric character. But how do I validate a string from user input?

    Is the user input Post data?

    then its easy:

    $bla = $HTTP_POST_VARS['bla'];

    ereg("[a-z]$", $bla) ;

    Or am i under rating your question?

      OK, It's not quite what I needed.

      Here's what I'm looking for:

      ereg("$user_input_data_variable$", $variable_to_find_it_in);

      I think the first "$" conflicts with the next "$" by ending the find string early. Know how to fix it?

        ereg("$user_input_data_variable$", $variable_to_find_it_in);

        try this way:
        ereg("\$user_input_data_variable$", $variable_to_find_it_in);

        or this way

        ereg("".$user_input_data_variable."$", $variable_to_find_it_in);

        AND DO NOT FORGET, that EREG functions is slower than preg functions in 10-100-1000 TIMES!!!!!!

          No, sorry. I've tried both of those already, and niether escaping the first "$", or concatenating (I hope that's spelled correctly) the validators with the variable seemed to work.

          This is what I originally had. In this case it will match "value", or "valueo" or "va", etc., because it's not completely validating it using ereg() :

          <?
          $array[] = "valueone";
          $array[] = "valuetwo";

          $countem = count($array);

          for ( $i=0;$i<$countem;$i++ ) {
          $allvalues .= $sites[$i] . "<br>";
          }

          if ( !ereg($user_input, $allvalues) ) {

          }
          ?>

          But I need the $user_input to match only one of the array values, exclusively. So it will not match "val" or "valueo" etc. It has to be the complete array value only.

            Like Yegg said, ereg is MUCH slower than preg_match.

            But your code won't work, because you don't have those $ anchors there any more (unless they're in $user_input already). I'm assuming that the reference to $sites was supposed to be to $array.

            Of course, putting the anchors in will break, because you've jammed all the arrays values together and there's nothing to distinguish where one ends and the next begins.

            Why not just:

            $array[]='valueone';
            $array[]='valuetwo';
            if(in_array($user_value,$array))
            {//$user_value maches an entry in the array...
            }

              Awesome! I just new that there was an array function somewhere out there that I simply didn't know about! Thanks a bunch!😃

                Write a Reply...