My Apologies, I have never gotten to grips with regex expressions.
I need to remove anything (from a product name, some of them have ampersands in them) that isnt alphanumeric from a string, excluding the spaces.
So far I have this (found from another stackoverflow post):
$productname = preg_replace("~[\W]~","",$product['name']);
Now this replaces everything that is alphanumeric with "". Which is fine, except I want to exclude spaces as It is currently removing all spaces. Also, i cannot find anywhere what the tilde (~
) does in regex.
With regards to the spaces, I have seen that there is a negative lookahead, achieved by ?!
, but how to incorporate that in the above I don't know.