[thelist] a PHP function question

Bob Meetin ontheroad at frii.com
Sun Feb 11 21:17:31 CST 2007


I'm writing a PHP function to censor particular phrases or words from a 
form, something like:

function censor ($data)
{
    $data = str_replace("gambling", "", $data);
    return $data;
}

and to call the function:

$whatever = censor($_POST['whatever']);

this works fine.  but what i would rather do is search for a string or 
substring and if found, set a variable such as $pass to no, echo an 
unacceptable content message, and prevent the form from submitting.  so 
i try something like the following:

function censor ($data)
   {
    if (eregi('[gambl]', $data)) { $message = "inappropriate content - submission denied"; $pass = "NO"; }
    return $data;
    echo "p: $pass<br>"; // this is just a test to see if the variable is set - and it fails.
   }

unfortunately calling the function doesn't return the $pass variable to 
the form (either within the function or in the form).  what am i missing?

-bob




More information about the thelist mailing list