Results 1 to 3 of 3
  1. #1

    Angry PHP eregi() function

    Arg! Can anyone tell me if I did something wrong here??

    eregi("*", $account) || eregi("/", $account) || eregi(":", $account) || eregi("?", $account) || eregi("\", $account) || eregi("|", $account) || eregi("<", $account) || eregi(">", $account)
    That's part of a bigger IF statement, but the rest of the statement is fine, there's something wrong with the code above.

  2. #2
    Help? Please?

  3. #3
    Join Date
    Oct 2001
    Yowzers! That might work but most of the characters you're searching for are special characters - they have a special meaning to the regular expression function itself. They need to be "escaped" with a backslash ( \ ) so it knows that "*" means "*" and not "match the previous character zero or more times"

    PHP Code:
    eregi("\*",$account) || eregi("\\",$account) || etc.... 
    But I would also shrink that down into a class - a set of characters you're looking for. If anything in that set is matched, the function returns true. And since it's inside a set, they don't need to be escaped. Try this:

    PHP Code:
    if (eregi("[*/:?\\|<>]"$account)) print "MATCH!"
    Notice I started with a list of the characters you wanted to match, and put them in brackets, like this "[*/:?\|<>]".

    Try that!
    Personal Life Timed Out Due To Inactivity

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts