I’m trying to figure out what this does, and how to change it.
preg_replace('/[^\w\s]/','',$var);
I THINK this replaces all symbols with nothing (deletes them basically). What if I want to allow some specific symbols, what do I change here?
For example I want replace everything EXCEPT:
- /
- numbers
- letters
- spaces
Thanks.
^means everything but this, so this replaces everything but word characters (\w) and whitespace (\s).To replace everything except the characters you mention, use this:
\/is the escaped version of/.