I saw this statement
$name = ereg_replace("[^A-Za-z0-9.]", "", $name);
What is the difference between [^A-Za-z0-9.] and [A-Za-z0-9.]?
Based on my understanding of regular expression, the [] is used to include all valid characters for replacment in function ereg_replace.
Then what is the purpose of including ^ into the []?
Thank you
The initial
^inside a character class[…]inverts the set of characters that are described inside the character class. While[A-Za-z0-9.]matches one character of the character set described byA-Za-z0-9.,[^A-Za-z0-9.]matches any other character except one of the characters described byA-Za-z0-9.. What these other characters are depends on the base character set the string is defined with.So
[abc]matches eithera,b, orcand[^abc]matches any other character excepta,b, andc. Your example code will remove any characters that are not described by[A-Za-z0-9.]. That leaves only characters of[A-Za-z0-9.].