I am trying to write a function in PHP using preg_replace where it will replace all those characters that are NOT found in the list. Usually we replace the place where they are found, but this is different.
For example, if I have a line:
$mystring = "ab2c4d";
I can write the following function, which will replace all numbers with *:
preg_replace("/(\d+)/","*",$mystring);
But I want to replace those characters that are neither a number nor the alphabets from a to z. They may be similar to # $ * (); ~! {} [] | \ /., <>? 'etc
So nothing but numbers and alphabets should be replaced by something else. How to do it?
thank
source
share