What is the best way to remove punctuation marks, symbols, diacritics, special characters?

前端 未结 2 1769
不知归路
不知归路 2021-01-11 09:30

I use these lines of code to remove all punctuation marks, symbols, etc as you can see them in the array,

$pattern_page = array(\"+\",\",\",\".\",\"-\",\"\'\         


        
2条回答
  •  独厮守ぢ
    2021-01-11 09:59

    Use classes:

    preg_replace('/[^[:alpha:]]/', '', $input);
    

    Would remove anything that's not considered a "character" by the currently set locale. If it's punctuation, you seek to eliminate, the class would be [:punct:].

    \W means "any non-word character" and is the opposite of \w which includes underscores (_).

提交回复
热议问题