Pretty straight-forward:
$string = preg_replace('/[^a-zA-Z0-9@.]+/', '', $string);
In simple English: Replace one or more occurrences of anything that's not an alphabet, number or the symbol @
, .
, with nothing.
Autopsy:
/
- starting delimiter[^a-zA-Z0-9@.]
- a character class^
- used to negate the character classa-zA-Z0-9
- alphabets or numbers@
- literal character@
.
- literal character.
+
- match the previous quantity one or more times/
ending delimiter