I have problems with removing special characters. I want to remove all special characters except "( ) / . % - &", because I'm setting that string as a title.
I edited code from the original (look below):
preg_replace('/[^a-zA-Z0-9_ -%][().][\/]/s', '', $String);
But this is not working to remove special characters like: "’s, "“", "â€", among others.
original code: (this works but it removes these characters: "( ) / . % - &")
preg_replace('/[^a-zA-Z0-9_ -]/s', '', $String);
You want str replace, because performance-wise it's much cheaper and still fits your needs!
(Unless this is all about security and sql injection, in that case, I'd rather to go with a POSITIVE list of ALLOWED characters... even better, stick with tested, proven routines.)
Btw, since the OP talked about title-setting: I wouldn't replace special chars with nothing, but with a space. A superficious space is less of a problem than two words glued together...