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);
See example.
Good try! I think you just have to make a few small changes:
[
and]
) inside the character class (which are also indicated by[
and]
)\
) itself-
is special: if it's between two characters, it means a range, but if it's at the beginning or the end, it means the literal-
character.You'll want something like this:
See http://docs.activestate.com/activeperl/5.10/lib/pods/perlrecharclass.html#special_characters_inside_a_bracketed_character_class if you want to read up further on this topic.
Your dot is matching all characters. Escape it (and the other special characters), like this: