Phantom wrote:
> What is a << Warning: Invalid preceding regular expression >> mean when
> running a page?
Some characters have special meaning in regex, and some combinations are
simply invalid.
You are iterating through one character at a time, and passing in such a
"combination" to regex.
Most importantly, you are pretty much doing it wrong. :-)
What you *SHOULD* be using is something more like this:
$validChars = '[^0-9A-Za-z]';
function invalid_string($string, $valid){
return ereg_replace($valid, '', $string);
}
And, actually, since your function is now a single line, you might as well
not bother having a function, eh?...
For sure, you should *NOT* be using a for loop to check each character one
at a time.
>
> Output -----------------------------------
> Warning: Invalid preceding regular expression in /ereg.php on line 4
>
> PHP Page Source -------------------------
>
> <%
> function invalid_string($string,$valid) {
> for ($i=0; $i<strlen($string); $i++) {
> if (!ereg ($string[$i], $valid)) return true; \\Line
> 4;
> }
> return false;
> }
>
> if ($Action=="Submit") {
> $validChars =
> "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
> $validAlphas = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
>
> $validNums = "1234567890";
> if (invalid_string($Word,$validChars)) $Msg = "You entered a bad
> word.";
> else $Msg = "That word is acceptable.";
> }
> %>
> <html>
> <head>
> <title>Ereg</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
>
> </head>
>
> <body bgcolor="#FFFFFF" text="#000000">
> <%=$Msg;%><title>EREG</title>
> <form name="form1" method="post" action="ereg.php">
> Please enter a valid word only. Only alphanumeric characters! I dare
> you to
> try anything else.<br>
> <input type="text" name="Word" size="20" maxlength="20">
> <input type="submit" name="Action" value="Submit">
> </form>
> </body>
> </html>
>
>
>
>
--
Like music? http://l-i-e.com/artists.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]